【发布时间】:2011-12-08 00:04:24
【问题描述】:
我的UITableViewCell 中有一个UIButton。此按钮启动 UIActionSheet,因此当用户从操作表中拍摄按钮时,我希望按钮的文本更改为该文本。
我使用以下代码显示按钮。我想如果我在actionSheet: clickedButtonAtIndex: 中调用'tableView reload' 会起作用,但有没有更好的选择来更新statusButton?
SmokingStatusTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.statusButton.titleLabel.text = [self.vitalsDictionary objectForKey:@"smoking_status_display"];
- (IBAction)smokingStatusButtonClicked:(id)sender{
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Smoking Status" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"1 Current everday smoker", @"2 Current some day smoker", nil];
self.smokingStatusActionSheet = actionSheet;
[self.smokingStatusActionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (actionSheet == self.smokingStatusActionSheet){
switch (buttonIndex) {
case 0:
[self.vitalsDictionary setObject:@"daily_smoker" forKey:@"smoking_status"];
break;
case 1:
[self.vitalsDictionary setObject:@"nondaily_smoker" forKey:@"smoking_status"];
break;
default:
break;
}
}
}
【问题讨论】:
标签: iphone objective-c cocoa-touch uitableview uibutton