Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 自定义tableview单元格未刷新_Iphone_Uitableview - Fatal编程技术网

Iphone 自定义tableview单元格未刷新

Iphone 自定义tableview单元格未刷新,iphone,uitableview,Iphone,Uitableview,这是我的自定义表视图单元格,我希望每1分钟更改一次这些值(值将从服务器加载)。我已经设置了Nstimer并尝试重新加载tableview。数组中的数据变化良好,但uitableviewcell中的值没有变化 代码: Tableviewcontroller.m -(void) loadView { parsejson = [ParseJson alloc]; defaults=[NSUserDefaults standardUserDefaults]; items=[NSArray array

这是我的自定义表视图单元格,我希望每1分钟更改一次这些值(值将从服务器加载)。我已经设置了Nstimer并尝试重新加载tableview。数组中的数据变化良好,但uitableviewcell中的值没有变化

代码:

Tableviewcontroller.m

-(void) loadView
{

parsejson = [ParseJson alloc];
defaults=[NSUserDefaults standardUserDefaults];

items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
usercount=[NSArray arrayWithObjects:
[parsejson getdata:[defaults valueForKey:@"userid"]],@" 0 ", nil];




    listtimer = [NSTimer scheduledTimerWithTimeInterval:60.0                // start timer ( interval 2 secs )
                                              target:self
                                            selector:@selector(reloadlist:)
                                            userInfo:nil
                                             repeats:YES];


}

- (void)reloadlist:(NSTimer*)timer
{
    NSLog(@"list reload " );

    items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
    usercount=[NSArray arrayWithObjects:
   [parsejson getdata:[defaults valueForKey:@"userid"]],@" 0 ", nil];


   //UITableView *tv = (UITableView *)self.view;
  [self.tableview reloadData];

   // NSIndexPath *a = [NSIndexPath indexPathForRow:0 inSection:0]; // I wanted to update this cell specifically
   // NearestListCell *c = (NearestListCell *)[tv cellForRowAtIndexPath:a];
    //c.count=[usercount objectAtIndex:0];
    //[tv beginUpdates];
   //// [tv reloadRowsAtIndexPaths:usercount withRowAnimation:UITableViewRowAnimationRight];
    //[tv endUpdates];
   // [tv reloadData];
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [usercount count];
}

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

    static NSString *CellIdentifier = @"NearmeListIdentifier";

    listCell *cell = (listCell *)[tableView     dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"listCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.text.text = [items objectAtIndex:indexPath.row];
    cell.data11.text = [usercount objectAtIndex:indexPath.row];
    cell.data22.text = @" 0.0 ";

    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath 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
-(void)viewDidLoad
{

    [super viewDidLoad];


    defaults = [NSUserDefaults standardUserDefaults];

    if (Tablecontroller == nil)
    {
        Tablecontroller = [[Tableviewcontroller alloc] init];
}
        [myTable setDataSource:Tablecontroller];

            [myTable setDelegate:Tablecontroller];

    Tablecontroller.view = Tablecontroller.tableView;



 }
    #import "ViewController1.h"

    @implementation ViewController

   - (id)initWithStyle:(UITableViewStyle)style
   {
      self = [super initWithStyle:style];
      if (self) {

       }
      return self;
   }

   - (void)viewDidLoad
   {
     [super viewDidLoad];

   }

   - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
    return 1;
  }

   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
     return [usercount count];
  }

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"NearmeListIdentifier";

      listCell *cell = (listCell *)[tableView     dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil)
      {
          NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"listCell" owner:self options:nil];
          cell = [nib objectAtIndex:0];
      }

     cell.text.text = [items objectAtIndex:indexPath.row];
     cell.data11.text = [usercount objectAtIndex:indexPath.row];
     cell.data22.text = @" 0.0 ";
     return cell;
  }

- (void)reloadlist:(NSTimer*)timer
{
    NSLog(@"list reload " );

   items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
   usercount=[NSArray arrayWithObjects:
   [parsejson getdata:[defaults valueForKey:@"userid"]],@" 0 ", nil];
   [self.tableView reloadData];
}


-(void) loadView
{

parsejson = [ParseJson alloc];
defaults=[NSUserDefaults standardUserDefaults];

items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
usercount=[NSArray arrayWithObjects:
[parsejson getdata:[defaults valueForKey:@"userid"]],@" 0 ", nil];




    listtimer = [NSTimer scheduledTimerWithTimeInterval:60.0                // start timer ( interval 2 secs )
                                              target:self
                                            selector:@selector(reloadlist:)
                                            userInfo:nil
                                             repeats:YES];


}
-(void) loadView
{

parsejson = [ParseJson alloc];
defaults=[NSUserDefaults standardUserDefaults];

items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
usercount=[NSArray arrayWithObjects:
[parsejson getdata:[defaults valueForKey:@"userid"]],@" 0 ", nil];

  **// removed the nstimer from here.** 

}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [usercount count];
}

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

// Added these 2 lines of code here.
    items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
    usercount=[NSArray arrayWithObjects:[parsejson getNearestUsercount:[defaults valueForKey:@"userid"]],@" 0 ", nil];


    static NSString *CellIdentifier = @"NearmeListIdentifier";

    listCell *cell = (listCell *)[tableView     dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"listCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.text.text = [items objectAtIndex:indexPath.row];
    cell.data11.text = [usercount objectAtIndex:indexPath.row];
    cell.data22.text = @" 0.0 ";

    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath 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
-(void)viewDidLoad
{

    [super viewDidLoad];


    defaults = [NSUserDefaults standardUserDefaults];

    if (Tablecontroller == nil)
    {
        Tablecontroller = [[Tableviewcontroller alloc] init];
}
        [myTable setDataSource:Tablecontroller];

            [myTable setDelegate:Tablecontroller];

    Tablecontroller.view = Tablecontroller.tableView;

// I Put the Nstimer here.

 aTimer = [NSTimer scheduledTimerWithTimeInterval:2.0                // start timer ( interval 2 secs )
                                              target:self
                                            selector:@selector(timerTicked:)
                                            userInfo:nil
                                             repeats:YES];


 }

- (void)timerTicked:(NSTimer*)timer
{
    [myTable.self reloadData];



}
Viewcontroller.m

-(void) loadView
{

parsejson = [ParseJson alloc];
defaults=[NSUserDefaults standardUserDefaults];

items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
usercount=[NSArray arrayWithObjects:
[parsejson getdata:[defaults valueForKey:@"userid"]],@" 0 ", nil];




    listtimer = [NSTimer scheduledTimerWithTimeInterval:60.0                // start timer ( interval 2 secs )
                                              target:self
                                            selector:@selector(reloadlist:)
                                            userInfo:nil
                                             repeats:YES];


}

- (void)reloadlist:(NSTimer*)timer
{
    NSLog(@"list reload " );

    items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
    usercount=[NSArray arrayWithObjects:
   [parsejson getdata:[defaults valueForKey:@"userid"]],@" 0 ", nil];


   //UITableView *tv = (UITableView *)self.view;
  [self.tableview reloadData];

   // NSIndexPath *a = [NSIndexPath indexPathForRow:0 inSection:0]; // I wanted to update this cell specifically
   // NearestListCell *c = (NearestListCell *)[tv cellForRowAtIndexPath:a];
    //c.count=[usercount objectAtIndex:0];
    //[tv beginUpdates];
   //// [tv reloadRowsAtIndexPaths:usercount withRowAnimation:UITableViewRowAnimationRight];
    //[tv endUpdates];
   // [tv reloadData];
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [usercount count];
}

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

    static NSString *CellIdentifier = @"NearmeListIdentifier";

    listCell *cell = (listCell *)[tableView     dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"listCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.text.text = [items objectAtIndex:indexPath.row];
    cell.data11.text = [usercount objectAtIndex:indexPath.row];
    cell.data22.text = @" 0.0 ";

    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath 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
-(void)viewDidLoad
{

    [super viewDidLoad];


    defaults = [NSUserDefaults standardUserDefaults];

    if (Tablecontroller == nil)
    {
        Tablecontroller = [[Tableviewcontroller alloc] init];
}
        [myTable setDataSource:Tablecontroller];

            [myTable setDelegate:Tablecontroller];

    Tablecontroller.view = Tablecontroller.tableView;



 }
    #import "ViewController1.h"

    @implementation ViewController

   - (id)initWithStyle:(UITableViewStyle)style
   {
      self = [super initWithStyle:style];
      if (self) {

       }
      return self;
   }

   - (void)viewDidLoad
   {
     [super viewDidLoad];

   }

   - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
    return 1;
  }

   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
     return [usercount count];
  }

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"NearmeListIdentifier";

      listCell *cell = (listCell *)[tableView     dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil)
      {
          NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"listCell" owner:self options:nil];
          cell = [nib objectAtIndex:0];
      }

     cell.text.text = [items objectAtIndex:indexPath.row];
     cell.data11.text = [usercount objectAtIndex:indexPath.row];
     cell.data22.text = @" 0.0 ";
     return cell;
  }

- (void)reloadlist:(NSTimer*)timer
{
    NSLog(@"list reload " );

   items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
   usercount=[NSArray arrayWithObjects:
   [parsejson getdata:[defaults valueForKey:@"userid"]],@" 0 ", nil];
   [self.tableView reloadData];
}


-(void) loadView
{

parsejson = [ParseJson alloc];
defaults=[NSUserDefaults standardUserDefaults];

items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
usercount=[NSArray arrayWithObjects:
[parsejson getdata:[defaults valueForKey:@"userid"]],@" 0 ", nil];




    listtimer = [NSTimer scheduledTimerWithTimeInterval:60.0                // start timer ( interval 2 secs )
                                              target:self
                                            selector:@selector(reloadlist:)
                                            userInfo:nil
                                             repeats:YES];


}
-(void) loadView
{

parsejson = [ParseJson alloc];
defaults=[NSUserDefaults standardUserDefaults];

items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
usercount=[NSArray arrayWithObjects:
[parsejson getdata:[defaults valueForKey:@"userid"]],@" 0 ", nil];

  **// removed the nstimer from here.** 

}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [usercount count];
}

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

// Added these 2 lines of code here.
    items=[NSArray arrayWithObjects:@" data1",@" data2 ", nil];
    usercount=[NSArray arrayWithObjects:[parsejson getNearestUsercount:[defaults valueForKey:@"userid"]],@" 0 ", nil];


    static NSString *CellIdentifier = @"NearmeListIdentifier";

    listCell *cell = (listCell *)[tableView     dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"listCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.text.text = [items objectAtIndex:indexPath.row];
    cell.data11.text = [usercount objectAtIndex:indexPath.row];
    cell.data22.text = @" 0.0 ";

    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath 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
-(void)viewDidLoad
{

    [super viewDidLoad];


    defaults = [NSUserDefaults standardUserDefaults];

    if (Tablecontroller == nil)
    {
        Tablecontroller = [[Tableviewcontroller alloc] init];
}
        [myTable setDataSource:Tablecontroller];

            [myTable setDelegate:Tablecontroller];

    Tablecontroller.view = Tablecontroller.tableView;

// I Put the Nstimer here.

 aTimer = [NSTimer scheduledTimerWithTimeInterval:2.0                // start timer ( interval 2 secs )
                                              target:self
                                            selector:@selector(timerTicked:)
                                            userInfo:nil
                                             repeats:YES];


 }

- (void)timerTicked:(NSTimer*)timer
{
    [myTable.self reloadData];



}
ViewController.h

@interface Viewcontroller : UIViewController
{

   Tableviewcontroller *Tablecontroller;
       IBOutlet UITableView *myTable;
}

@end
#import <UIKit/UIKit.h>

@interface ViewController : UITableViewController

@end
请尝试此代码,如果遇到任何问题,请告诉我。谢谢

ViewController.h

@interface Viewcontroller : UIViewController
{

   Tableviewcontroller *Tablecontroller;
       IBOutlet UITableView *myTable;
}

@end
#import <UIKit/UIKit.h>

@interface ViewController : UITableViewController

@end
请尝试此代码,如果遇到任何问题,请告诉我。谢谢你为什么不试试

[self.tableView reloadData];
而不是

   UITableView *tv = (UITableView *)self.view;
  [tv reloadData];
仅当您的超类是UITableViewController时才可以。如果不是,则为tableView创建一个出口并通过它重新加载表格

您是否将此“setNeedsDisplay”用作

[cell.data11 setNeedsDisplay] if cellForRow is calling.
你为什么不试试

[self.tableView reloadData];
而不是

   UITableView *tv = (UITableView *)self.view;
  [tv reloadData];
仅当您的超类是UITableViewController时才可以。如果不是,则为tableView创建一个出口并通过它重新加载表格

您是否将此“setNeedsDisplay”用作

[cell.data11 setNeedsDisplay] if cellForRow is calling.

请尝试此代码:它在这里工作正常

/* FirstTVContoller.h */

#import <Foundation/Foundation.h>

@interface FirstTVContoller : UITableViewController <UITableViewDataSource, UITableViewDelegate>{
    NSMutableArray *items;
}

@end


/* FirstTVContoller.m */

#import "FirstTVContoller.h"
#import "SecondTVController.h"

@implementation FirstTVContoller


-(void) loadView
{
    if (items == nil) {
        items = [[NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"6",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",nil] retain];
    }
}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
    return [items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewStylePlain reuseIdentifier:@"MyIdentifier"];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"1.%@" ,[items objectAtIndex:indexPath.row]];
    return cell;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

        return UITableViewCellEditingStyleDelete;

}
- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath {

    if(editingStyle == UITableViewCellEditingStyleDelete) {     
        //Delete the object from the table.
        [items removeObjectAtIndex:indexPath.row];
        [tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

-(void) dealloc
{
    [items release];
    [super dealloc];
}

@end





/* SecondTVController.h */




#import <Foundation/Foundation.h>


@interface SecondTVController : UITableViewController <UITableViewDataSource, UITableViewDelegate>{
    int numberOfCells;
}

@end


/* SecondTVController.m */

#import "SecondTVController.h"


@implementation SecondTVController
-(void) viewDidLoad
{
    numberOfCells = 20;
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
    return numberOfCells;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:@"MyIdentifier"];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"2.%d",  indexPath.row];

    return cell;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    return UITableViewCellEditingStyleDelete;

}
- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath {

    if(editingStyle == UITableViewCellEditingStyleDelete) {     
        //Delete the object from the table.
        numberOfCells -=1;
        [tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
    }
}

@end

/* TwoTableViewsViewController.h */


#import <UIKit/UIKit.h>
#import "FirstTVContoller.h"
#import "SecondTVController.h"

@interface TwoTableViewsViewController : UIViewController{
    FirstTVContoller *firstController;
    SecondTVController *secondController;
    IBOutlet UITableView *firstTable;
    IBOutlet UITableView *secondTable;
}

@end


/* TwoTableViewsViewController.m */

#import "TwoTableViewsViewController.h"

@implementation TwoTableViewsViewController

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    if (firstController == nil) {
        firstController = [[FirstTVContoller alloc] init];
    }
    if (secondController == nil) {
        secondController = [[SecondTVController alloc] init];
    }
    [firstTable setDataSource:firstController];
    [secondTable setDataSource:secondController];

    [firstTable setDelegate:firstController];
    [secondTable setDelegate:secondController];
    firstController.view = firstController.tableView;
    secondController.view = secondController.tableView;
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)dealloc {
    [firstController release];
    [secondController release];
    [firstTable release];
    [secondTable release];
    [super dealloc];
}
/*FirstTVContoller.h*/
#进口
@interface FirstTvController:UITableViewController{
NSMutableArray*项;
}
@结束
/*FirstTVContoller.m*/
#导入“FirstTvController.h”
#导入“SecondTVController.h”
@实现控制器
-(void)负荷视图
{
如果(项目==零){
items=[[NSMutableArray数组,其对象为:@“1”、“2”、“3”、“4”、“5”、“6”、“6”、“8”、“9”、“10”、“11”、“12”、“13”、“14”、“15”、“16”、“17”、“零];
}
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
返回1;
}
-(NSInteger)表格视图:(UITableView*)表格行数节:(NSInteger)节
{
返回[项目计数];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:@“MyIdentifier”];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:@“MyIdentifier”];
}
cell.textLabel.text=[NSString stringWithFormat:@“1.%@,[items objectAtIndex:indexPath.row]];
返回单元;
}
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
[tableView取消行索引路径:indexPath动画:是];
}
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{
返回UITableViewCellEditingStyleDelete;
}
-(无效)表格视图:(UITableView*)电视提交编辑样式:(UITableViewCellEditingStyle)编辑样式
ForRowatineXpath:(NSIndexPath*)indexPath{
如果(editingStyle==UITableViewCellEditingStyleDelete){
//从表中删除对象。
[items removeObjectAtIndex:indexath.row];
[tv deleteRowsatindExpath:[NSArray arrayWithObject:indexPath]带RowAnimation:UITableViewRowAnimationFade];
}
}
-(无效)解除锁定
{
[项目发布];
[super dealoc];
}
@结束
/*第二个tvcontroller.h*/
#进口
@接口SecondTVController:UITableViewController{
int细胞数;
}
@结束
/*第二台tvcontroller.m*/
#导入“SecondTVController.h”
@第二个控制器的实现
-(无效)viewDidLoad
{
细胞数=20;
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
返回1;
}
-(NSInteger)表格视图:(UITableView*)表格行数节:(NSInteger)节
{
返回细胞数;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:@“MyIdentifier”];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellSelectionStyleNone重用标识符:@“MyIdentifier”];
}
cell.textLabel.text=[NSString stringWithFormat:@“2.%d”,indexath.row];
返回单元;
}
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
[tableView取消行索引路径:indexPath动画:是];
}
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{
返回UITableViewCellEditingStyleDelete;
}
-(无效)表格视图:(UITableView*)电视提交编辑样式:(UITableViewCellEditingStyle)编辑样式
ForRowatineXpath:(NSIndexPath*)indexPath{
如果(editingStyle==UITableViewCellEditingStyleDelete){
//从表中删除对象。
细胞数-=1;
[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationRight];
}
}
@结束
/*TwoTableViewsViewController.h*/
#进口
#导入“FirstTvController.h”
#导入“SecondTVController.h”
@界面TwoTableViewsViewController:UIViewController{
FirstTvController*firstController;
SecondTVController*secondController;
IBUITableView*第一个表;
IBUITableView*第二个表;
}
@结束
/*TwoTableViewsViewController.m*/
#导入“TwoTableViewsViewController.h”
@实现TwoTableViewsViewController
//实现viewDidLoad以在加载视图(通常从nib)后执行附加设置。
-(无效)viewDidLoad{
[超级视图下载];
if(firstController==nil){
firstController=[[FirstTvController alloc]init];
}
if(secondController==nil){
secondController=[[SecondTVController alloc]init];
}
[firstTable setDataSource:firstController];
[secondTable setDataSource:secondController];
[firstTable setDelegate:firstController];
[secondTable setDelegate:secondController];
firstController.view=firstController.tableView;
secondController.view=secondController.tableView;
}
-(无效)未收到记忆警告{
//如果视图没有superview,则释放该视图。
[超级记忆警告];
//释放所有未使用的缓存数据、图像等。
}
-(无效)解除锁定{
[第一控制器释放];