特定のセルを開示インジケーター付きで使用して a を表示しようとしていますUIImagePicker
(他のセルにUITextFields
は などがあります) UIButton
。アクションをセルに接続したいのですが、新しいセグエを作成するしかありません。どうすればいいですか?
3 に答える
1
セクションと行のインデックスをハードコーディングしたくない場合は、次のようにすることができます。
.h ファイルで、IB を使用して IBOutlets を作成します。
@property (weak, nonatomic) IBOutlet UITableViewCell *upgradeAppCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *spreadTheWordCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *rateOnAppStoreCell;
.m ファイル:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell == upgradeAppCell)
{
[self upgradeApp];
}
else if (cell == spreadTheWordCell)
{
[self spreadTheWord];
}
else if (cell == rateOnAppStoreCell)
{
[self rateOnAppStore];
}
}
于 2014-11-23T21:29:28.433 に答える
1
タップ可能にしたいセルのインデックスパスがわかっている場合(リストの最初のセルなど)。次に、次を使用できます。
-(void) tableview:(UITableView *)tableview didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 && indexPath.row == 0) {
// do some action
[tableview deslectRowAtIndexPath:indexPath];
[self someAction];
}
}
また、cellForRowAtIndexPath 内の他のすべてのセルをタップ イベントに応答しないように設定することもできます。
于 2012-11-22T01:09:56.147 に答える
0
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *identifier = @"identifier";
YourCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if(!cell)
{
cell = /*Create your cell*/
[cell.button addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
}
cell.button.tag = [indexPath row];
return cell;
}
-(void)didClickButton:(UIButton *)button
{
int row = button.tag
/*Here you'll be able to know the button of which row has been clicked.*/
}
于 2012-11-22T01:01:15.627 に答える