基本方式不起作用.
for index in 0 ..< list.count {
if list[index] == nil {
list.removeAtIndex(index) //this will cause array index out of range
}
}
Run Code Online (Sandbox Code Playgroud) 在iPhone App中单击表格视图单元格我要显示表格视图单元格附件类型在didSelectRowAtIndexPath上的复选标记我正在编写代码
if(indexPath.row ==0)
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType=UITableViewCellAccessoryCheckmark;
}
Run Code Online (Sandbox Code Playgroud)
并显示复选标记.
但在我的情况下,我想允许用户一次只检查单元格意味着如果用户选择其他行然后应该检查该行并且之前检查应该是未选中的
我怎样才能做到这一点?
我是ios开发的新手,我在一个单元格中使用了checkmark UITableView.
我想在NSUserDefaults数据库中存储已检查的单元格,当我重新加载应用程序时,将显示之前选中的已检查单元格,我尝试不同的方式,但仍未能实现它.
有人可以帮帮我吗?我将非常感激.对不起,我的英语不好.
我的代码如下:
#import "FirstRowSubview.h"
@interface FirstRowSubview ()
@end
@implementation FirstRowSubview
@synthesize array = _array;
@synthesize lastIndexPath = _lastIndexPath;
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *list = [[NSMutableArray alloc] initWithObjects:@"ffgfgh", @"564654", @"56548", @"fgmjfgmf", @"ggkdj", nil];
self.array = list;
[list release];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.array = nil;
}
#pragma mark -
#pragma mark - TableView Datasource Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ …Run Code Online (Sandbox Code Playgroud)