大佬教程收集整理的这篇文章主要介绍了iphone – iOS5上的NSIndexPath崩溃,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (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_I@L_155_9@m() == UIUserInterfaceI@L_155_9@mPad) { 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; }
以上是大佬教程为你收集整理的iphone – iOS5上的NSIndexPath崩溃全部内容,希望文章能够帮你解决iphone – iOS5上的NSIndexPath崩溃所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。