Iphone 向单元逻辑问题添加按钮
我在一个单元格中添加了一个按钮,所以如果有10个单元格,每个单元格将有一个按钮 这就是我将按钮添加到单元格的方式 在Iphone 向单元逻辑问题添加按钮,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我在一个单元格中添加了一个按钮,所以如果有10个单元格,每个单元格将有一个按钮 这就是我将按钮添加到单元格的方式 在cellforrowatinexpath UIButton *but= [UIButton buttonWithType:UIButtonTypeCustom]; [but addTarget:self action:@selector(submitReceiptButtonClicked:)forControlEven
cellforrowatinexpath
UIButton *but= [UIButton buttonWithType:UIButtonTypeCustom];
[but addTarget:self
action:@selector(submitReceiptButtonClicked:)forControlEvents:UIControlEventTouchDown];
but.frame = CGRectMake(0,0,200,30);
[cell.contentView addSubview:but];
单击此按钮时,我将使用UIAlertView警告用户,如果用户在AlertView中单击OK,我需要将该按钮的文本更改为Done
在中,单击按钮索引
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
NSString *name= [alertView buttonTitleAtIndex:buttonIndex];
if([name isEqualToString:@"OK"])
{
// Here i need to change the text of the Button (which is in a cell) to `Done`.
}
当用户单击UIAlertVIew的OK按钮时,我需要将按钮的文本更改为
Done
(此按钮应属于我单击的单元格。其他单元格中的按钮不应更改)。1将按钮标记设为indexPath.row+aConstant
2在submitReceiptButtonClicked:(id)发送方读取按钮标签并将其放入全局NSInteger
3在alertView中,委托获取带有
cellForRowAtIndexPath:
的单元格,IndexXPath将是[nsIndexXPath indexPathForRow:YourSavedIntegrater-aConstant inSection:0]
然后从单元格的内容视图中获取按钮UIButton*myButton=(UIButton*)[cell.contentView view with tag:yourSavedInteger]编码>并更改按钮标题。因此,如果用户执行快速滚动,它是否仍然有效?若单元格被重复使用,会发生什么情况?您将更改错误单元格上的标题。若要Illep Yes,它将起作用,但您必须在数组中搜索更改的按钮或名称。在cellForRow中读取该数组。因为单元格可以重用,但indexPath将有所不同