无法重新加载提供EXC_BAD_ACCESS的表

时间:2012-05-22 08:21:23

标签: iphone uitableview uitextfield reload

尝试重新加载表格时给出BAD_EXCESS信号。

在下面的代码中。

-(void)textFieldDidEndEditing:(UITextField *)textField {
    NSLog(@"%d",textField.tag);
    if (textField.tag == 2) {
            IntelligentPillBoxAppDelegate *appdelegate = (IntelligentPillBoxAppDelegate *)[[UIApplication sharedApplication]delegate];
            appdelegate.strip1_detail = [pillboxDb get_detail_for_din:value];

            [table reloadData];
    }
    [textField resignFirstResponder];
}

+(NSMutableArray*)get_detail_for_din:(int) din{
NSArray *arrDocPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *strDestPath = [NSString stringWithFormat:@"%@/samplepillbox1.sqlite",[arrDocPath objectAtIndex:0]];

//IntelligentPillBoxAppDelegate *appdelegate = (IntelligentPillBoxAppDelegate *)[[UIApplication sharedApplication]delegate];
//appdelegate.strip1_detail = [[NSMutableArray alloc]init];
NSMutableArray *strip1_detail = [[NSMutableArray alloc]init];
sqlite3 *db;
if(sqlite3_open([strDestPath UTF8String], &db)==SQLITE_OK)

{

    NSString *query = [NSString stringWithFormat:@"select * from maintable_master where din =%d ",din];

    void* v;
    char* err_msg;
    sqlite3_stmt *studentStmt;

    if(sqlite3_prepare_v2(db, [query UTF8String], -1, &studentStmt, &err_msg)==SQLITE_OK)
    {
        while (sqlite3_step(studentStmt)==SQLITE_ROW) {

            int din = sqlite3_column_int(studentStmt, 0);
            NSString *brandname = [NSString stringWithUTF8String: sqlite3_column_text(studentStmt, 1)];
            NSString *fullname = [NSString stringWithUTF8String: sqlite3_column_text(studentStmt, 2)];
            NSString *strength = [NSString stringWithUTF8String: sqlite3_column_text(studentStmt, 3)];
            NSString *medicationtype =[NSString stringWithUTF8String: sqlite3_column_text(studentStmt, 4)];
            NSString *presciptionid= [NSString stringWithUTF8String: sqlite3_column_text(studentStmt, 5)];
            //float marks = sqlite3_column_double(studentStmt, 2);

            //pillbox *st = [[pillbox alloc]init];
            //st.Din = sno;
            //st.Name = sname;

            //NSLog(@"%@",st);

            Strip_items *si = [[Strip_items alloc]init];
            si.Din = din;
            si.BrandName = brandname;
            si.FullName = fullname;
            si.Strength = strength;
            si.MedicationType = medicationtype;
            si.PresciptionID = presciptionid; 
            NSLog(@"%@",si.BrandName);
            NSLog(@"%d",si.Din);
            NSLog(@"%@",si.FullName);
            NSLog(@"%@",si.Strength);
            NSLog(@"%@",si.MedicationType);
            NSLog(@"%@",si.PresciptionID);



            [strip1_detail addObject:si];
        }

    }

}
return strip1_detail;}

3 个答案:

答案 0 :(得分:1)

启用僵尸对象,它会告诉你发生了什么错误。

转到产品>编辑方案> enabl zombi对象

答案 1 :(得分:1)

您似乎没有定义所有变量。

检查value的定义位置及其值。

此外,您可能首先辞职文本字段的响应者,然后重新加载表格视图。根据您的代码,在您重新加载表视图后,您辞职的第一个响应者可能不再存在的文本字段。

答案 2 :(得分:0)

你在这一行得到了BAD_EXCESS ...... 有关IntelligentPillBoxAppDelegate

的代码的更多解释
appdelegate.strip1_detail = [pillboxDb get_detail_for_din:value];