2011-11-30 53 views
1

我試圖訪問在一個視圖控制器中聲明的屬性和對象,在我需要它們的頁面中。通過繼承視圖控制器來實現。但是我遇到了問題在這裏,繼承控制器正在使控制器覆蓋。我的意思是子類控制器的導航欄和標題視圖顯示在使用的視圖中。當我刪除[super viewDidLoad]方法時,需要顯示的視圖不是越來越displayed.Also繼承視圖控制器的標題視圖越來越displayed.I並使用下面的語句繼承:我也張貼代碼:使用繼承控制器覆蓋標題查看標題

ERViewEditController class: 

    @interface ERViewEditController:ERAddReminderController 
    { 

     UITableView *theTable; 

    } 

    @property(nonatomic,retain) IBOutlet UITableView *theTable; 

    @end 

    @implementation ERViewEditController 

    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
    - (void)viewDidLoad 
    { 
     self.view.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"bg.jpg"]]; 
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(pop:)]; 
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(edit:)]; 

     [self setTitle:@"Reminders Listed"]; 

     [self.theTable reloadData]; 
     [super viewDidLoad]; 
    } 

    - (UITableViewCell *)tableView:(UITableView *)view cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

     NSString *CellId = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row]; 

     UITableViewCell *cell = (UITableViewCell *)[view dequeueReusableCellWithIdentifier:CellId]; 

     UILabel *label1 = [[[UILabel alloc]initWithFrame:CGRectMake(54, 3, 100, 40)]autorelease]; 
     label1.backgroundColor = [UIColor clearColor]; 
     label1.textColor = [UIColor whiteColor]; 

     UILabel *label2 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease]; 
     label2.backgroundColor = [UIColor clearColor]; 
     label2.textColor = [UIColor whiteColor]; 

     UILabel *label3 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 100, 40)]autorelease]; 
     label3.backgroundColor = [UIColor clearColor]; 
     label3.textColor = [UIColor whiteColor]; 

     if (cell == nil) 
     { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellId] autorelease]; 
      view.backgroundColor = [UIColor clearColor]; 
      cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"reminderbutton.png"]]; 

      if (indexPath.section == 0) 
      { 
       UILabel *label = [[[UILabel alloc]initWithFrame:CGRectMake(20, 3, 280, 40)]autorelease]; 
       label.backgroundColor = [UIColor clearColor]; 
       label.text = @" ID Name  Event   Date"; 
       label.textColor = [UIColor cyanColor]; 
       [cell addSubview:label]; 
      } 

      else if (indexPath.section == 1) 
      { 
       const char *dbpath = [databasePath UTF8String]; 
       sqlite3_stmt *statement; 

       if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK) 
       { 
        NSString *querySQL = [NSString stringWithFormat:@"SELECT name,event,date FROM reminders"]; 

        const char *query_stmt = [querySQL UTF8String]; 

        if (sqlite3_prepare_v2(remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK) 
        { 
         if (sqlite3_step(statement) == SQLITE_ROW) 
         { 
          NSString *nameField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]; 

          NSString *eventField = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];      

          NSString *dateField = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]; 

          [nameField stringByAppendingString:eventField]; 

          label1.text = nameField; 
          label2.text = eventField; 
          label3.text = dateField; 
         } 

         sqlite3_finalize(statement); 
        } 
        sqlite3_close(remindersDB); 
       } 

       switch (indexPath.row) 
       { 
        case 0: 
         [cell addSubview:label1]; 
         [cell addSubview:label2]; 
         [cell addSubview:label3]; 
         break; 

        default: 
         break; 
       } 

      } 

     } 

     return cell; 

    } 


My navigation bar issue is resolved,now I have still been facing the header view title issue,I used the following code to fix: 

-(NSString *)tableView:(UITableView *)atableView titleForHeaderInSection:(NSInteger)section 
{ 
    return @""; 
} 

但不工作請幫我擺脫這種感謝Mr.Ben的答案:)

我也有一個問題,請檢查太多,如果可能的話,在此先感謝:)

Populate the table view sections with rows of table in sqlite database in an order

回答

1

您的描述有點令人困惑,但聽起來您的超類在設置子類後設置了標題/按鈕信息。重新排序你的viewDidLoad,使[super viewDidLoad];首先在函數中,任何子類的變化將在超類設置它後應用。

+0

Ben Yeah我明白了,謝謝你的回答,這對導航欄問題非常合適。但是標題視圖仍然被繼承視圖控制器覆蓋,請幫我解決這個問題! –

+0

請參閱編輯的答案和屏幕截圖Mr.Ben,在此先感謝:) –

+0

本人發現解決方案,爲什麼繼承控制器的標題視圖正在顯示... 由於視圖控制器是subclassed所有功能,如導航酒吧,標題視圖等將出現,因此我們需要實現超類的所有方法,即 正如我已經實現 - (UIView的*)的tableView:(UITableView的*)atableView viewForHeaderInSection:(NSInteger的)與標題繼承控制器部分, 我們需要實現同樣的方法,只是返回nil來解決這些問題 無論如何,感謝大家對我的問題的耐心和迴應,再次感謝......再見TC。 –