标题视图标题被继承的控制器覆盖

时间:2011-11-30 09:41:15

标签: iphone uitableview uinavigationbar subclassing qheaderview

我正在尝试访问在一个视图控制器中声明的属性和对象到我需要它们的页面。通过子类化视图控制器来这么做。但是这里有一个问题,继承的控制器正在制作控制器被覆盖。我的意思是子类控制器的导航栏和标题视图将显示在使用的视图中。当我删除[super viewDidLoad]方法时,需要显示的窗口不会显示。也是标题视图继承的视图控制器正在显示。我使用以下语句进行了子类化:我也发布了代码:

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 个答案:

答案 0 :(得分:1)

您的描述有点令人困惑,但听起来您的超类在设置子类后设置标题/按钮信息。重新命令你的viewDidLoad所以[super viewDidLoad];在函数中是第一个,然后在超类设置它之后应用任何子类更改。