iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – iOS5上的NSIndexPath崩溃大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序工作正常,直到iOS5. @H_673_5@ @H_673_5@@L_618_0@一个分组的tableview有2个部分.每个部分都有1个选项,使用UITableViewCellAccessorycheckmark显示.

@H_673_5@当我尝试确定是否([lasTindexPath1 isEqual:indexPath])时,我的应用程序在iOS5中崩溃了

@H_673_5@更新:以下全部相关代码

@H_673_5@lasTindexPath1和lasTindexPath2都是我在头文件中声明的NSIndexPath对象.数字1跟踪第0部分中的最后一个indexPath,数字2跟踪第1部分.

@H_673_5@
- (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;
}

解决方法

lasTindexPath1是如何定义的,具有什么属性?你能尝试通过类使用self.lasTindexPath1吗?

大佬总结

以上是大佬教程为你收集整理的iphone – iOS5上的NSIndexPath崩溃全部内容,希望文章能够帮你解决iphone – iOS5上的NSIndexPath崩溃所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。