
我有一个分组的tablevIEw有2个部分.每个部分都有1个选项,使用UItableVIEwCellAccessorycheckmark显示.
当我尝试确定是否([lastIndexPath1 isEqual:indexPath])时,我的应用程序在iOS5中崩溃了
更新:以下全部相关代码:
lastIndexPath1和lastIndexPath2都是我在头文件中声明的NSIndexPath对象.数字1跟踪第0部分中的最后一个indexPath,数字2跟踪第1部分.
- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; self.vIEw.backgroundcolor = [UIcolor whitecolor]; //Initialize the array.listofItems = [[NSMutableArray alloc] init];NSArray *Fontname = [NSArray arrayWithObjects:@"Baskerville",@"Palatino",@"Times New Roman",@"Verdana",nil];NSDictionary *FontnameInDict = [NSDictionary dictionaryWithObject:Fontname forKey:@"FontOptions"];NSArray *FontSize = [NSArray arrayWithObjects:@"Der var engang",@"Der var engang",nil];NSDictionary *FontSizeInDict = [NSDictionary dictionaryWithObject:FontSize forKey:@"FontOptions"];[listofItems addobject:FontnameInDict];[listofItems addobject:FontSizeInDict];}- (voID)vIEwWillAppear:(BOol)animated { [super vIEwWillAppear:animated]; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; //SET SKRIFTTYPE Nsstring *neverOpendFonts1 = [prefs objectForKey:@"neverOpendFonts1"]; if (![neverOpendFonts1 isEqualToString:@"1"]) { lastIndexPath1 = [NSIndexPath indexPathForRow:1 inSection:0]; UItableVIEwCell *newCell = [mytableVIEw cellForRowAtIndexPath:lastIndexPath1]; newCell.accessoryType = UItableVIEwCellAccessorycheckmark; Nsstring *lastIndexPathString1 = [Nsstring stringWithFormat:@"1"]; [prefs setobject:lastIndexPathString1 forKey:@"lastIndexPath1"]; Nsstring *Fontname = [Nsstring stringWithFormat:@"Palatino"]; [prefs setobject:Fontname forKey:@"Fontname"]; neverOpendFonts1 = [Nsstring stringWithFormat:@"1"]; [prefs setobject:neverOpendFonts1 forKey:@"neverOpendFonts1"]; [prefs synchronize]; NSLog(@"Har aldrig været åbnet - Font options"); } else { NSInteger row = [[prefs objectForKey:@"lastIndexPath1"] intValue]; NSLog(@"Font ROW: %i",row); lastIndexPath1 = [NSIndexPath indexPathForRow:row inSection:0]; UItableVIEwCell *newCell = [mytableVIEw cellForRowAtIndexPath:lastIndexPath1]; newCell.accessoryType = UItableVIEwCellAccessorycheckmark; } //SET SKRIFT STØRRELSE Nsstring *neverOpendFonts2 = [prefs objectForKey:@"neverOpendFonts2"]; if (![neverOpendFonts2 isEqualToString:@"1"]) { if (UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiomPad) { lastIndexPath2 = [NSIndexPath indexPathForRow:2 inSection:1]; UItableVIEwCell *newCell2 = [mytableVIEw cellForRowAtIndexPath:lastIndexPath2]; newCell2.accessoryType = UItableVIEwCellAccessorycheckmark; Nsstring *lastIndexPathString2 = [Nsstring stringWithFormat:@"2"]; [prefs setobject:lastIndexPathString2 forKey:@"lastIndexPath2"]; Nsstring *FontSize = [Nsstring stringWithFormat:@"24.0"]; [prefs setobject:FontSize forKey:@"FontSize"]; neverOpendFonts2 = [Nsstring stringWithFormat:@"1"]; [prefs setobject:neverOpendFonts2 forKey:@"neverOpendFonts2"]; [prefs synchronize]; } else { lastIndexPath2 = [NSIndexPath indexPathForRow:0 inSection:1]; UItableVIEwCell *newCell3 = [mytableVIEw cellForRowAtIndexPath:lastIndexPath2]; newCell3.accessoryType = UItableVIEwCellAccessorycheckmark; Nsstring *lastIndexPathString2 = [Nsstring stringWithFormat:@"0"]; [prefs setobject:lastIndexPathString2 forKey:@"lastIndexPath2"]; Nsstring *FontSize = [Nsstring stringWithFormat:@"16.0"]; [prefs setobject:FontSize forKey:@"FontSize"]; neverOpendFonts2 = [Nsstring stringWithFormat:@"1"]; [prefs setobject:neverOpendFonts2 forKey:@"neverOpendFonts2"]; [prefs synchronize]; } } else { NSInteger row2 = [[prefs objectForKey:@"lastIndexPath2"] intValue]; NSLog(@"FontSIZE ROW: %i",row2); lastIndexPath2 = [NSIndexPath indexPathForRow:row2 inSection:1]; UItableVIEwCell *newCell2 = [mytableVIEw cellForRowAtIndexPath:lastIndexPath2]; newCell2.accessoryType = UItableVIEwCellAccessorycheckmark; } [mytableVIEw reloadData];}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section { //Number of rows it should expect should be based on the section NSDictionary *dictionary = [listofItems objectAtIndex:section]; NSArray *array = [dictionary objectForKey:@"FontOptions"]; return [array count];}- (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw { return [listofItems count];}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { static Nsstring *CellIDentifIEr = @"Cell"; UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr]; if (cell == nil) { // cell = [[[UItableVIEwCell alloc] initWithFrame:CGRectZero reuseIDentifIEr:CellIDentifIEr] autorelease]; cell = [[[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:CellIDentifIEr] autorelease]; } // Set up the cell... //First get the dictionary object NSDictionary *dictionary = [listofItems objectAtIndex:indexPath.section]; NSArray *array = [dictionary objectForKey:@"FontOptions"]; Nsstring *cellValue = [array objectAtIndex:indexPath.row]; cell.textLabel.text = cellValue; if (indexPath.section == 0) { if([lastIndexPath1 isEqual:indexPath]) { cell.accessoryType = UItableVIEwCellAccessorycheckmark; } else { cell.accessoryType = UItableVIEwCellAccessoryNone; } switch (indexPath.row) { case 0: { cell.textLabel.Font = [UIFont FontWithname:@"Baskerville" size:24]; } break; case 1: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:24]; } break; case 2: { cell.textLabel.Font = [UIFont FontWithname:@"Times New Roman" size:24]; } break; case 3: { cell.textLabel.Font = [UIFont FontWithname:@"Verdana" size:24]; } break; } } if (indexPath.section == 1) { if([lastIndexPath2 isEqual:indexPath]) { cell.accessoryType = UItableVIEwCellAccessorycheckmark; } else { cell.accessoryType = UItableVIEwCellAccessoryNone; } switch (indexPath.row) { case 0: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:16]; } break; case 1: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:20]; } break; case 2: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:24]; } break; case 3: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:28]; } break; case 4: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:32]; } break; case 5: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:36]; } break; case 6: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:40]; } break; case 7: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:44]; } break; case 8: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:48]; } break; case 9: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:52]; } break; case 10: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:56]; } break; case 11: { cell.textLabel.Font = [UIFont FontWithname:@"Palatino" size:60]; } break; } } return cell;}解决方法 lastIndexPath1是如何定义的,具有什么属性?你能尝试通过类使用self.lastIndexPath1吗? 总结 以上是内存溢出为你收集整理的iphone – iOS5上的NSIndexPath崩溃全部内容,希望文章能够帮你解决iphone – iOS5上的NSIndexPath崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)