“隐形”行崩溃应用程序

时间:2014-04-08 17:29:39

标签: ios uitableview

我添加了一个搜索功能来搜索用户名,但是第一个单元格是不可见的,如果偶然你按下它会导致应用程序崩溃。找到用户名后,您可以轻松点击添加。

我认为问题出现在我的搜索代码中,但我似乎无法自行修复。

// Make Sure It Is Not Empty And Query Parse For Username In Field 
if (![searchText isEqualToString:@""]) {

    PFQuery *query = [PFUser query];
    [query whereKey:@"username" equalTo:searchText];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            // Check To See If A User Is Actually Found
            if (objects.count > 0) {

                //  Return The User Found
                self.allUsers = objects;


                //set the user as the table views data source and reload the table view


                // Error Message If Username Is Not Found
            }
            else {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Username Not Found" message:@"Try again with a valid username" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                [alertView show];

            }

            [self.tableView reloadData];

        } else {
        }
    }];
}

}

我还尝试将返回数字更改为0.隐形单元格消失,但搜索结果将不会显示。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

// Return the number of sections.
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.user) {

    //a user was found, we need to display one row.
    return 1;
} else {

    //a user was not found/searched for yet, dont display any rows
    return 0;
}
// Return the number of rows in the section.

return [self.allUsers count];
}

0 个答案:

没有答案