【发布时间】:2012-03-17 07:36:22
【问题描述】:
我有我的数组:
self.colorNames = [[NSArray alloc]
initWithObjects:@"Red", @"Green",
@"Blue", @"Indigo", @"Violet", nil];
我已经尝试了所有能找到的方法,但总是有错误。我希望能够滑动以显示删除按钮,然后按删除按钮并删除该行。
完整代码(与表格相关的所有内容):
// HEADER FILE
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *tableView;
NSMutableArray *colorNames;
}
@property (strong, nonatomic) NSArray *colorNames;
@end
// IMPLEMENTATION
#import "ViewController.h"
@implementation ViewController
@synthesize colorNames;
- (void)viewDidLoad {
[super viewDidLoad];
self.colorNames = [[NSMutableArray alloc]
initWithObjects:@"Red", @"Green",
@"Blue", @"Indigo", @"Violet", nil];
[super viewDidLoad];
//[tableView setEditing:YES animated:NO];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int count = [colorNames count];
return count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell.
cell.textLabel.text = [self.colorNames objectAtIndex: [indexPath row]];
return cell;
}
【问题讨论】:
-
您只在此处发布了
NSArray。请发布您如何设置UITableView的相关代码。 -
它就在那里。请提供您可能有的任何可能的意见,因为我感谢任何形式的帮助。
标签: ios objective-c uitableview cocoa-touch