Pushing UITableView to UITableView



我似乎无法推动到另一个UITableView。当我运行代码时,它只显示EventType,当单击时,它会向另一个UITableView发送推送,显示Events。假设代码将一个UITableView推送到另一个UITableView。请有人帮我解决这个问题。我认为它来自RootViewController,但我似乎无法确定问题所在。

应用程序运行正常,但我无法推送到其他TableViewController。这是使用的代码。这是使用的代码,但它并没有真正揭示太多,因为大多数设置都是使用IB完成的

这是RootViewController.m-我认为问题来自于此,但我似乎无法从哪里确定

#import "RootViewController.h"
#import "EventTypeViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
@synthesize eventType;

- (void) viewDidLoad
{
    eventType = [[NSMutableArray alloc]init];
    [eventType addObject:@"Corporate"];
    [eventType addObject:@"Social"];
    [eventType addObject:@"Dining"];
    [self setTitle: @"Events"];

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

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

- (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:@"Cell"];

         cell.textLabel.text = [[eventType objectAtIndex:indexPath.row]retain];
         [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        return cell;

    }

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    EventTypeViewController *events = [[EventTypeViewController alloc] initWithNibName:@"EventTypeViewController" bundle:nil];
    if ([[eventType objectAtIndex:indexPath.row] isEqual:@"Corporate"])
    {
        events.eventsInt = 0;
        [events setTitle:[eventType objectAtIndex:indexPath.row]];
    }
    if ([[eventType objectAtIndex:indexPath.row] isEqual:@"Social"])
    {
        events.eventsInt = 1;
        [events setTitle:[eventType objectAtIndex:indexPath.row]];
    }
    if ([[eventType objectAtIndex:indexPath.row] isEqual:@"Dining"]) {
        events.eventsInt = 2;
        [events setTitle:[eventType objectAtIndex:indexPath.row]];
    }
    [self.navigationController pushViewController:events animated:YES];
}
@end

这是EventTypeViewController.m-我没什么好说的。

#import "EventTypeViewController.h"
@interface EventTypeViewController ()
@end
@implementation EventTypeViewController
@synthesize eventsInt;

- (void)viewDidLoad
{
    corporateArray = [[NSMutableArray alloc]
                      initWithObjects:@"Corporate 1", @"Corporate 2", @"Corporate 3", @"Corporate 4", nil];
    socialArray = [[NSMutableArray alloc]
                   initWithObjects:@"Social 1", @"Social 2", nil];
    diningArray = [[NSMutableArray alloc]
                   initWithObjects:@"Dining 1", @"Dining 2", @"Dining 3", nil];

}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (eventsInt == 0)
        return [corporateArray count];
    if (eventsInt == 1)
        return [socialArray count];
    if (eventsInt == 2)
        return [diningArray count];
    [self.tableView reloadData];
}
- (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:@"Cell"]autorelease];
    }
    // Configure the cell...
    if (eventsInt == 0)
        cell.textLabel.text = [[corporateArray objectAtIndex:indexPath.row]retain];
    if (eventsInt == 1)
        cell.textLabel.text = [[socialArray objectAtIndex:indexPath.row]retain];
    if (eventsInt == 2)
        cell.textLabel.text = [[diningArray objectAtIndex:indexPath.row]retain];
    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    return cell;
}
@end

UITableViewController是否嵌入了UINavigationController?这样你就可以激活push方法。

你也可以使用segues。实现-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender,为那里的下一个控制器设置数据变量,并使用[self performSegueWithIdentifier:(NSString *) sender:(id)sender] 推送

最新更新