Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone,如何在简单的表视图设置屏幕上存储/加载一个值?_Iphone_Objective C_Xcode - Fatal编程技术网

iPhone,如何在简单的表视图设置屏幕上存储/加载一个值?

iPhone,如何在简单的表视图设置屏幕上存储/加载一个值?,iphone,objective-c,xcode,Iphone,Objective C,Xcode,这是我的cellForRowAtIndexPath,我为一行加载了一个值,而不是从一个简单数组中加载一个值并将其转换为一行 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView

这是我的cellForRowAtIndexPath,我为一行加载了一个值,而不是从一个简单数组中加载一个值并将其转换为一行

- (UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
    CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 
        reuseIdentifier:CellIdentifier] autorelease];
}
NSInteger row = [indexPath row];
cell.textLabel.text = [dayArray objectAtIndex:row];
NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];
NSInteger startRow = [myDefaults integerForKey:kStartRow];
if (startRow == row) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
    cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
这里是我保存值的地方,请注意,我每次都使用kStartRow和数组值

- (void)tableView:(UITableView *)tableView 
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int newRow = [indexPath row];
NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];
[myDefaults setInteger:newRow forKey:kStartRow]; // Set the tablecell 
[myDefaults setObject:[dayArray objectAtIndex:newRow] forKey:kNSUEndOfMonthDay];
[myDefaults synchronize];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView reloadData];
 [self.navigationController popViewControllerAnimated:YES];
}
现在,当我想在应用程序首次运行时设置默认值时,使用两个值会有点混乱。如何使用一个存储值进行管理

cell.accessoryType = indexPath.row == [dayArray indexOfObject:[[NSUserDefaults standardUserDefaults] objectForKey:kNSUEndOfMonthDay]] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;

我还不明白您在存储什么。您的数据是什么样子的?通过kStartRow,我存储了行索引,我想去掉它。使用kNSUEndOfMonthDay,我存储了一些简单的字符串。我希望能够将此值从字符串数组转换为行索引。字符串数组是否只包含每个元素一次?这会在编辑之前或之后为每个元素打勾?:)我已经粘贴了两次复选标记,而不是第二个元素没有。。。