Iphone 调用视图将出现在UITableviewController中

Iphone 调用视图将出现在UITableviewController中,iphone,objective-c,ios,xcode,uitableview,Iphone,Objective C,Ios,Xcode,Uitableview,我正在尝试调用UITableView的[MyTableviewController.tableview重载数据]函数。我认为最好的方法是UITableViewController子类的-(void)viewwillbeen方法 代码在创建类时不知何故没有创建,我尝试实现该方法,但几乎没有成功 在对SO和其他各种网站进行了一些研究之后,我发现有迹象表明,问题可能在于UIViewController子类是导航控制器的一部分,而导航控制器又是选项卡栏控制器的一部分。发布的一般建议和代码是将一个(哪个?

我正在尝试调用UITableView的
[MyTableviewController.tableview重载数据]
函数。我认为最好的方法是UITableViewController子类的
-(void)viewwillbeen
方法

代码在创建类时不知何故没有创建,我尝试实现该方法,但几乎没有成功

在对SO和其他各种网站进行了一些研究之后,我发现有迹象表明,问题可能在于UIViewController子类是导航控制器的一部分,而导航控制器又是选项卡栏控制器的一部分。发布的一般建议和代码是将一个(哪个?)控制器子类化,并实现
-viewwillbeen
消息

我的问题是: 1.有没有一种方法可以调用这个急需的方法,而不必对另一个控制器进行子类化? 2.如果是,我该如何做? 3.如果没有,请你确切地向我解释我必须做什么,更重要的是,为什么我必须这样做

以下是UITableViewController的完整代码:

//
//  OverViewController.m
//  NoificationTest
//
//  Created by Mirko Winckel on 15.03.12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "OverViewController.h"
#import "SecondOverViewController.h"
#import "Globals.h"

@interface OverViewController ()

@end

@implementation OverViewController

@synthesize entrys;



- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self) {
        // Custom initialization
    }
    return self;
}



- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.tableView reloadData];

    if (entrys == nil) 
    {

    NSString* filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString* fileName = [[Globals sharedGlobals].selectedProject stringByAppendingString:@".csv"];
    NSString* fileAtPath = [filePath stringByAppendingPathComponent:fileName];
    NSString* content = [[NSString alloc] initWithData:[NSData dataWithContentsOfFile:fileAtPath] encoding:NSUTF8StringEncoding];
    NSString *stringToFind =@"\n";
    entrys = [content componentsSeparatedByString:stringToFind];

    }


    /* Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;*/
}

- (void)viewDidUnload{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

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

    int weeks = 1+1;

    return weeks;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    NSString *sectionHeader = nil;

    if ( section == 0 ) {

       sectionHeader = @"Refresh - test";

    }

    if (  section == 1 ) {
        if ( [Globals sharedGlobals].selectedProject != nil){

            NSString* temp = @"Current in project ";
            [temp stringByAppendingString:[Globals sharedGlobals].selectedProject];

            sectionHeader = temp;

        }

        else {
            sectionHeader = @"No project selected";
        }
    }

    if (  section == 2 ) {
        sectionHeader = @"Week 3";
    }

    if (  section == 3 ) {
        sectionHeader = @"Week 4";
    }

    if (  section == 4 ) {
        sectionHeader = @"Week 5";
    }

    return sectionHeader;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int rows;

    if (section == 0){
        rows = 1;
    }

    if (section == 1 ){
        rows = [entrys count] -1;
    }



    return rows ;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
           cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSString *oneLine = [entrys objectAtIndex:indexPath.row];
    NSArray *lineComponents = [oneLine componentsSeparatedByString:@";"];

    cell.textLabel.text = [lineComponents objectAtIndex:0];
    cell.textLabel.textColor = [UIColor colorWithRed:0.0 green:0.8 blue:0.2 alpha:1.0];

    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{



    if (indexPath.section == 0) {

        [self.tableView reloadData];

        [tableView deselectRowAtIndexPath:indexPath animated:YES];



    }






    if (indexPath.section == 1) {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    SecondOverViewController *anotherViewController = [[SecondOverViewController alloc] initWithStyle:UITableViewStylePlain];

    NSArray *rowArray = [[entrys objectAtIndex:indexPath.row] componentsSeparatedByString:@";"];

    anotherViewController.oneRow = rowArray;

    [self.navigationController pushViewController:anotherViewController animated:YES];

    } 





    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */

}

@end
//
//概览控制器.m
//去核试验
//
//由Mirko Winckel于2012年3月15日创建。
//版权所有(c)2012年\uuuu MyCompanyName\uuuuu。版权所有。
//
#导入“OverViewController.h”
#导入“SecondOverViewController.h”
#导入“Globals.h”
@界面概览控制器()
@结束
@实现概述控制器
@综合入口;
-(id)initWithStyle:(UITableViewStyle)样式
{
self=[super initWithStyle:UITableViewStyleGrouped];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
[self.tableView重载数据];
if(entrys==nil)
{
NSString*filePath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0];
NSString*fileName=[[Globals sharedGlobals].selectedProject stringByAppendingString:@.csv“];
NSString*fileAtPath=[filePath stringByAppendingPathComponent:fileName];
NSString*content=[[NSString alloc]initWithData:[NSData dataWithContentsOfFile:fileAtPath]编码:NSUTF8StringEncoding];
NSString*stringToFind=@“\n”;
entrys=[content componentsSeparatedByString:stringToFind];
}
/*取消对下一行的注释以保留演示文稿之间的选择。
//self.clearselectiononviewwillappear=否;
//取消对以下行的注释,以在此视图控制器的导航栏中显示编辑按钮。
//self.navigationItem.rightBarButtonItem=self.editButtonItem*/
}
-(无效)视图卸载{
[超级视频下载];
//释放主视图的所有保留子视图。
//例如,self.myOutlet=nil;
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{
返回(interfaceOrientation==UIInterfaceOrientationGraphic);
}
#pragma标记-表视图数据源
-(NSInteger)表格视图中的节数:(UITableView*)表格视图{
整数周=1+1;
返回周;
}
-(NSString*)表格视图:(UITableView*)表格视图标题标题标题部分:(NSInteger)部分{
NSString*sectionHeader=nil;
如果(节==0){
sectionHeader=@“刷新-测试”;
}
如果(节==1){
if([Globals sharedGlobals].selectedProject!=nil){
NSString*temp=@“项目中当前”;
[temp stringByAppendingString:[Globals sharedGlobals].selectedProject];
节头=温度;
}
否则{
sectionHeader=@“未选择任何项目”;
}
}
如果(节==2){
sectionHeader=@“第3周”;
}
如果(节==3){
sectionHeader=@“第4周”;
}
如果(节==4){
sectionHeader=@“第5周”;
}
返回段标题;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
int行;
如果(节==0){
行=1;
}
如果(节==1){
行=[入口计数]-1;
}
返回行;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier];
}
NSString*oneLine=[entrys objectAtIndex:indexath.row];
NSArray*lineComponents=[oneLine Components由字符串分隔:@];“];
cell.textlab.text=[lineComponents objectAtIndex:0];
cell.textlab.textColor=[UIColor colorWithRed:0.0绿色:0.8蓝色:0.2阿尔法:1.0];
返回单元;
}
/*
//替代以支持表视图的条件编辑。
-(BOOL)tableView:(UITableView*)tableView caneditrowatinexpath:(nsindepath*)indepath
{
//如果不希望指定的项可编辑,则返回“否”。
返回YES;
}
*/
/*
//替代以支持编辑表格视图。
-(void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)行的编辑样式索引路径:(NSIndexPath*)索引路径
{
如果(editingStyle==UITableViewCellEditingStyleDelete){
//从数据源中删除该行
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]和RowAnimation:UITableViewRowAnimationFade];
}   
else if(editingStyle==UITableViewCellEditingStyleInsert){
//创建相应类的新实例,将其插入数组,并向表视图添加新行
}   
}
*/
/*
//替代以支持重新排列表视图。
-(void)tableView:(UITableView*)tableView移动rowatinexpath:(nsindepath*)从indepath到indepath:(nsindepath*)到indepath
{
}
*/
/*
//重写以支持表视图的条件重新排列。
-(BOOL)tableView:(UITableView*)tableView可以移动rowatinexpath:(nsindepath*)indepath
{
//返回号
[self.tableView reloadData];
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView reloadData];
}