Bau*_*aub 0 iphone xcode objective-c uitableview ios
我有一个indexPath.row,它是1并且记录1(当使用NSLog时).如果我调用indexPath.row-1(应返回0),则返回4294967295.
我正在尝试返回,objectAtIndex:indexPath.row-1
但是当我得到4294967295时.
有任何想法吗?
- (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...
Singleton *singleton = [Singleton sharedSingleton];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if ([[prefs objectForKey:@"isYes"]boolValue] == 1 && randomMarker != 100)
{
//sets cell image
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,98,100)];
imgView.image = [UIImage imageNamed:@"stackoverflow.png"];
cell.imageView.image = imgView.image;
//sets cell text
cell.textLabel.text = @"Text";
self.checkedInCount == 100;
}
else if ([[prefs objectForKey:@"isYes"]boolValue] == 1 && randomMarker == 100)
{
//gets cell and cleans up cell text
NSLog(@"%@", indexPath.row);
NSString *title = [[[singleton linkedList]objectAtIndex:(indexPath.row-1)]objectForKey:@"desc"];
Run Code Online (Sandbox Code Playgroud)
Pen*_*One 10
当您尝试给unsigned int(NSUInteger
)一个负值时,它通常会返回一个非常大的正值.
你在打电话
NSString *tempDesc = [[[singleton linkedList]objectAtIndex:indexPath.row-1]objectForKey:@"desc"];
Run Code Online (Sandbox Code Playgroud)
什么时候indexPath.row
有价值0
,所以翻译是:
NSString *tempDesc = [[[singleton linkedList]objectAtIndex:-1]objectForKey:@"desc"];
Run Code Online (Sandbox Code Playgroud)
由于objectAtIndex:
将无符号整数作为其参数,-1
因此将其转换为垃圾值4294967295
.
为了避免这个问题,不减去1
从0
先检查indexPath.row
是积极的.
这是另一个问题:
NSLog(@"%@", indexPath.row);
Run Code Online (Sandbox Code Playgroud)
这应该是:
NSLog(@"%u", indexPath.row);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2464 次 |
最近记录: |