1
我正在使用XCode的基於導航的應用程序模板來創建以UITableView爲中心的應用程序。我有一些問題刪除tableView中的一些行。 在所有tableViews細胞我已通過繼承的UITableViewCell這樣增加了一個按鈕:來自外部RootViewController的deleteRowsAtIndexPaths類
當按鈕被按下在RoutinesAppDelegate.m方法「routineDone」TableViewCell.h:
@implementation TableViewCell
@synthesize button;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
RoutinesAppDelegate *appDelegate = (RoutinesAppDelegate *) [[UIApplication sharedApplication]delegate];
// Initialization code
button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[button setFrame:CGRectMake(320.0 - 90.0, 6.0, 80.0, 30.0)];
[button setTitle:@"Done" forState:UIControlStateNormal];
[button addTarget:appDelegate action:@selector(routineDone) forControlEvents:UIControlEventTouchUpInside];
button.hidden = YES;
[self.contentView addSubview:button];
}
return self;
}
被調用。
該方法是這樣的:
RoutinesAppDelegate.m
-(void) routineDone
{
if ([[NSFileManager defaultManager] fileExistsAtPath:[self todayListPath]])
{
int indexToRemove = buttonIndex + 1;
todayListArray = [NSMutableArray arrayWithContentsOfFile:[self todayListPath]];
[todayListArray removeObjectAtIndex:indexToRemove];
[todayListArray writeToFile:[self todayListPath] atomically:YES];
}
}
此方法從陣列,所述的tableView負載移除的項。這工作正常。
我的問題: 單擊按鈕時,單元格不會從屏幕上移除。
在RoutinesAppDelegate.m我試圖用
[tableView reloadData]
,但它似乎並沒有從RootViewController的類以外的地方工作。
這將是很好,如果我以某種方式可以使用deleteRowsAtIndexPaths方法,但我不知道如何從RootViewController類的外部commitEditingStyle調用該方法。
所以我的問題是:如何使細胞消失? :)
你如何得到'buttonIndex'? – 2011-05-29 20:21:28
@Deepak在'didSelectRowAtIndexPath:'方法我把:'appDelegate.buttonIndex = indexPath.row;' – steak2002 2011-05-29 20:30:59