UIViewControllerのサブクラスであるFirstViewControllerという名前のクラスがあり、そのクラスにUITableViewがあります。行が押されたときに、このクラスから新しいUIViewControllerサブクラス(セグエを使用)に移行する必要があります。
コードを使用してFirstViewControllerをUITableViewDelegateとUITableViewDataSourceにしました-
@interface FirstViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
このコード行でエラーが発生します-
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
tableViewはUIViewControllerクラスではなくUITableViewControllerにあるため、この問題を修正するにはどうすればよいですか?
編集 -
これが私のテーブルビューに関連するコードです-
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [sarray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellId = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if(cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
NSString *text = [sarray objectAtIndex:[indexPath row]];
cell.textLabel.text = text;
return cell;
}