掲示板を開発しています。
投稿フォームからテキストを入力して掲示板へ反映させ、
掲示板にコピーボタンを配置して、そのテキストをコピーしたいとおもっています。
どのようにしたらコピーできるでしょうか。
現在は、storybordsを使用して、UITableviewcell内(掲示板)のコピーしたいテキスト(msg)にcopytfを繋げるとエラーになってしまいます。
コードは下記となります。
【JEViewController.h】
@interface JEViewController : UIViewController<UITableViewDelegate,UITableViewDataSource> {
IBOutlet UITableView *tblTest;
NSMutableArray *_records;
UILabel *lbl1;
UILabel *lbl2;
}
@property (weak, nonatomic) IBOutlet UILabel *copytf;
- (IBAction)pushcopy:(id)sender;
@end
@interface NSString (URLEncoding)
- (NSString *)urlencode;
- (NSString *)urldecode;
@end
@interface JEViewController ()
@property (nonatomic) NSMutableArray *records;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UITextField *userTextField;
@property (weak, nonatomic) IBOutlet UITextField *msgTextField;
- (IBAction)refreshAction:(UIBarButtonItem *)sender;
- (IBAction)editAction:(UIBarButtonItem *)sender;
- (IBAction)searchAction:(UIButton *)sender;
- (IBAction)postAction:(UIButton *)sender;
- (void)requestGetUser:(NSString *)user;
- (void)requestPostUser:(NSString *)user msg:(NSString *)msg;
- (void)requestDeleteDocId:(NSString *)docId;
@end
@implementation JEViewController
@synthesize records = _records;
@synthesize copytf;
- (IBAction)pushcopy:(id)sender {
UIPasteboard *board = [UIPasteboard generalPasteboard];
[board setValue:copytf.text forPasteboardType:@"public.utf8-plain-text"];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:copytf.text message:@"コピーしました" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[av show];
}
- (void)viewDidLoad {
[super viewDidLoad];
tblTest.delegate = self;
tblTest.dataSource = self;
[self requestGetUser:nil];
}
- (void)viewDidUnload
{
[self setCopytf:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _records.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSDictionary *rec = [_records objectAtIndex:indexPath.row];
NSString *user = [rec objectForKey:@"user"];
NSString *msg = [rec objectForKey:@"msg"];
lbl1 = (UILabel *)[cell viewWithTag:1];
lbl2 = (UILabel *)[cell viewWithTag:2];
lbl1.text = user;
lbl2.text = msg;
tableView.separatorColor = [UIColor clearColor];
return cell;
}
開発は1年弱の経験となりますが掲示板は初めてなので、
ご教授いただけると助かります。
宜しくお願い致します。