好的,这是我目前在我的应用程序中所拥有的,主视图具有包含不同任务的tableview。当你触摸它时,它会推送到DetailViewController。我一直在尝试在detailview中制作内部tableview。所以我现在有一个TableController但是现在当我点击一个任务它就冻结了。
更新已添加的代码:
//RootViewController
#import "RootViewController.h"
#import "DetailViewController.h"
@implementation RootViewController
@synthesize toolbar;
@synthesize window;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
theArray = [[NSArray alloc] initWithObjects:@"Kill Taylor",@"Stab Taylor",@"Pay Jordan",nil];
//theArray = [[NSMutableArray alloc] init];
[super viewDidLoad];
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonPressed)];
self.navigationItem.rightBarButtonItem = addButton;
self.navigationItem.leftBarButtonItem = self.editButtonItem;
//self.navigationItem.rightBarButtonItem = addButton;
// self.navigationItem.rightBarButtonItem = addButton;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
//return UITableViewCellAccessoryDetailDisclosureButton;
return UITableViewCellAccessoryDetailDisclosureButton;
}
-(void) addButtonPressed
{
NSString *selectedAction = @"add";
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedAction = selectedAction;
//dvController.selectedTask = selectedTask;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [theArray count];
}
// Customize the appearance of table view cells.
- (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] autorelease];
}
cell.textLabel.text = [theArray objectAtIndex:indexPath.row];
return cell;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
if (editing)
{
// turn on the "add" button when editing
//self.navigationItem.rightBarButtonItem = addButton;
}
else
{
// remove the "add" butto when not editing
//self.navigationItem.rightBarButtonItem = nil;
}
[super setEditing:editing animated:animated];
}
/*
// 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 -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedAction = @"details";
NSString *selectedTask = [theArray objectAtIndex:indexPath.row];
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedAction = selectedAction;
dvController.selectedTask = selectedTask;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
上述所有作品
#import "DetailViewController.h"
@implementation DetailViewController
@synthesize selectedTask;
@synthesize selectedAction;
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
if(selectedAction == @"details"){
[super viewDidLoad];
self.navigationItem.title = @"Task Details";
//lblText.text = selectedTask;
}
else if(selectedAction == @"add"){
[super viewDidLoad];
self.navigationItem.title = @"Add Task";
//lblText.text = selectedTask;
}
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[selectedTask release];
[lblText release];
[super dealloc];
}
@end
如果它有任何构建内部表的东西,这不起作用。
答案 0 :(得分:1)
我认为问题可能出在DetailedViewController中的viewDidLoad方法中。修复以下两件事,看看是否有所作为。
这是你的代码,经过调整:
- (void)viewDidLoad
{
[super viewDidLoad];
if(selectedAction isEqualToString: @"details")
{
self.navigationItem.title = @"Task Details";
//lblText.text = selectedTask;
}
else if (selectedAction isEqualToString: @"add")
{
self.navigationItem.title = @"Add Task";
//lblText.text = selectedTask;
}
}