2010年10月8日金曜日

よく使うTableViewDelegate

//セクション数
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return num;
}
//セル生成
-(UITableViewCell*)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexpath{
static NSString*TableIdentifier=@"tablename";

UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:TableIdentifier];
if(cell==nil){
cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:TableIdentifier]autorelease];
}

NSInteger row= indexpath.row;
cell.textLabel.text=@"セルに表示する文字";
//cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

return cell;
}

//セル選択時
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath*)indexPath{
//選択解除
[tableView deselectRowAtIndexPath:[ tableView indexPathForSelectedRow] animated:YES];
NSUInteger row =[indexPath row];
}