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