gpt4 book ai didi

iphone - 从 UItableViewCell 调用 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:11:32 28 4
gpt4 key购买 nike

我正在尝试制作我的第一个应用程序。我有 6 个文件:

LeftPanelViewController.h LeftPanelViewController.m LeftPanelViewController.xib ForecastViewController.h ForecastViewController.m ForecastViewController.xib

在 LeftPanelViewController.xib 中,我有一个包含 TableView 的 View 。我想从我在 LeftPanelViewController.xib 中的 TableView 中设置一个单元格,这样当我按下该单元格时,我将能够调用我在 ForecastViewController.xib 中的 View 。

在我在 LeftPanelTableViewController.m 中的代码下方

#import "LeftPanelViewController.h"
#import "ForecastViewController.h"


@interface LeftPanelViewController ()

@property (nonatomic, weak) IBOutlet UITableView *myTableView;
@property (nonatomic, weak) IBOutlet UITableViewCell *cellMain;
@property (copy, nonatomic) NSArray *MRP;

@end

@implementation LeftPanelViewController

- (void)viewDidLoad
{
[super viewDidLoad];

Array = [[ NSMutableArray alloc] init];
[Array addObject:@"Forecast"];
[Array addObject:@"Inventory"];

}

- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [Array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:SimpleTableIdentifier];

//add an image to the tablecell
UIImage *image = [UIImage imageNamed:@"Icon.png"];
cell.imageView.image = image;

}
cell.textLabel.text = [Array objectAtIndex:indexPath.row];

if (indexPath.row < 7) {
cell.detailTextLabel.text = @"Account";
} else {
cell.detailTextLabel.text = @"Settings";
}
return cell;
}

- (void)viewDidUnload
{
[super viewDidUnload];
}

#pragma mark -
#pragma mark View Will/Did Appear

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}

#pragma mark -
#pragma mark View Will/Did Disappear

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}

#pragma mark -
#pragma mark Array Setup


#pragma mark -
#pragma mark UITableView Datasource/Delegate

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


#pragma mark -
#pragma mark Default System Code

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
}
return self;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];

}

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

if ([[Array objectAtIndex:indexPath.row] isEqual:@"Forecast"]) {

ForecastViewController *Forecast = [[ ForecastViewController alloc] initWithNibName:@"ForecastViewController" bundle:nil];
[self.navigationController pushViewController:Forecast animated:YES];

}


[tableView deselectRowAtIndexPath:indexPath animated:YES];
}



@end

最佳答案

代替

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

使用

[self presentViewController:Forecast animated:YES completion:nil];

关于iphone - 从 UItableViewCell 调用 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18305321/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com