prepareForSegue我的代码中的问题是什么,它不起作用

时间:2017-02-23 01:55:53

标签: ios objective-c segue

这是我的代码,我不知道有什么问题 有人可以帮帮我吗? 谢谢。 这是prepareForSegue方法

中的代码
  -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if (self.keyWord.text.length > 0) {
        NSString * keyWord =self.keyWord.text;
        sqlite3 * database;
        sqlite3_open([[self dbPath] UTF8String], &database);
        const char * selectSQL = "select * from word_inf where word like ?";
        sqlite3_stmt * stmt;
        int queryResult = sqlite3_prepare_v2(database, selectSQL, -1, &stmt, nil);
        NSMutableArray * result = [[NSMutableArray alloc] init];
        if (queryResult == SQLITE_OK) {
            sqlite3_bind_text(stmt, 1, [[NSString stringWithFormat:@"%%%@%%%",keyWord] UTF8String], -1, NULL);
            while (sqlite3_step(stmt) == SQLITE_ROW) {
                int word_id = sqlite3_column_text(stmt, 0);
                char * word = (char*)sqlite3_column_text(stmt, 1);
                char* detail = (char*)sqlite3_column_text(stmt, 2);
                MyWord * wordObj = [[MyWord alloc] initWithId:word_id word:[NSString stringWithUTF8String:word] detail:[NSString stringWithUTF8String:detail]];
                [result addObject:wordObj];
            }
        }
        sqlite3_close(database);
        DicTableViewController* resultViewController = (DicTableViewController*)segue.destinationViewController;
        resultViewController.wordArray = [result copy];
    }
}

这是cellForRowAtIndecPath方法

中的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"cellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    MyWord * wordObj = [self.wordArray objectAtIndex:indexPath.row];
    UITextField * word = (UITextField * )[cell viewWithTag:1];
    UITextField * detail =(UITextField * )[cell viewWithTag:2];
    word.text = wordObj.word;
    detail.text = wordObj.detail;

    return cell;
}

问题是它无法转向TableView,我不知道它有什么问题。 我想prepareForSegue的代码有问题,可能wordArray没有得到价值,但我确信result有价值,有人可以帮我吗? enter image description here

2017-02-23 10:01:14.549546 note[2625:66178] subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2017-02-23 10:01:14.552413 note[2625:66178] subsystem: com.apple.UIKit, category: HIDEventIncoming, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2017-02-23 10:01:14.568519 note[2625:66161] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2017-02-23 10:01:14.588178 note[2625:66108] subsystem: com.apple.UIKit, category: StatusBar, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2017-02-23 10:01:14.679790 note[2625:66108] subsystem: com.apple.BackBoardServices.fence, category: App, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2017-02-23 10:01:18.909319 note[2625:66108] subsystem: com.apple.UIKit, category: Touch, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2017-02-23 10:01:18.910011 note[2625:66108] subsystem: com.apple.UIKit, category: Gesture, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2017-02-23 10:01:18.910748 note[2625:66108] subsystem: com.apple.UIKit, category: GestureEnvironment, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2017-02-23 10:01:18.911257 note[2625:66108] subsystem: com.apple.UIKit, category: GestureExclusion, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2017-02-23 10:01:24.476483 note[2625:66108] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/easerliu/Library/Developer/CoreSimulator/Devices/D586AACB-7D56-47D9-9570-AF908DD3C8C8/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-02-23 10:01:24.476789 note[2625:66108] [MC] Reading from private effective user settings.
2017-02-23 10:01:24.504921 note[2625:66108] subsystem: com.apple.BackBoardServices.fence, category: Observer, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2017-02-23 10:01:24.505283 note[2625:66108] subsystem: com.apple.BackBoardServices.fence, category: Workspace, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2017-02-23 10:01:24.505559 note[2625:66108] subsystem: com.apple.BackBoardServices.fence, category: Trace, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2017-02-23 10:01:26.054137 note[2625:66108] subsystem: com.apple.libsqlite3, category: logging, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2017-02-23 10:01:27.210 note[2625:66108] -[UITableViewCellContentView setText:]: unrecognized selector sent to instance 0x7fb291d04220
2017-02-23 10:01:27.213 note[2625:66108] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellContentView setText:]: unrecognized selector sent to instance 0x7fb291d04220'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010a87034b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000109eb421e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010a8dff34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x000000010a7f5c15 ___forwarding___ + 1013
    4   CoreFoundation                      0x000000010a7f5798 _CF_forwarding_prep_0 + 120
    5   note                                0x0000000109798cd4 -[DicTableViewController tableView:cellForRowAtIndexPath:] + 356
    6   UIKit                               0x000000010ae00ba9 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 757
    7   UIKit                               0x000000010ae00e07 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
    8   UIKit                               0x000000010add4871 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3295
    9   UIKit                               0x000000010ae0a189 -[UITableView _performWithCachedTraitCollection:] + 110
    10  UIKit                               0x000000010adf09e3 -[UITableView layoutSubviews] + 222
    11  UIKit                               0x000000010ad58344 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
    12  QuartzCore                          0x000000010f3a3cdc -[CALayer layoutSublayers] + 146
    13  QuartzCore                          0x000000010f3977a0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    14  QuartzCore                          0x000000010f39761e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    15  QuartzCore                          0x000000010f32562c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
    16  QuartzCore                          0x000000010f352713 _ZN2CA11Transaction6commitEv + 475
    17  UIKit                               0x000000010acbe878 _afterCACommitHandler + 346
    18  CoreFoundation                      0x000000010a814e17 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    19  CoreFoundation                      0x000000010a814d87 __CFRunLoopDoObservers + 391
    20  CoreFoundation                      0x000000010a7f9b9e __CFRunLoopRun + 1198
    21  CoreFoundation                      0x000000010a7f9494 CFRunLoopRunSpecific + 420
    22  GraphicsServices                    0x000000010e4a3a6f GSEventRunModal + 161
    23  UIKit                               0x000000010ac93f34 UIApplicationMain + 159
    24  note                                0x000000010979a3bf main + 111
    25  libdyld.dylib                       0x000000010c63068d start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

1 个答案:

答案 0 :(得分:0)

问题在于这个表达式:cell viewWithTag:1。您不小心将标记1分配到故事板中的错误视图。您将其分配给单元格的内容视图,而不是(或除此之外)将其分配给文本字段。