So I need your help please!
I've created a UITableViewController: ContactDetailViewController.
In IB in the nib file, I've added a view ahead of the table view and hooked it up to headerView - a UIView declared in the .h file.
I've also created a view: CustomerHeaderView
However when I run the code below, Its throwing an exception at the following line:
headerView = [[UIView alloc] initWithNibName:#"ContactHeaderDetail" bundle:nil];
The error being thrown is:
2010-05-20 10:59:50.405 X[19620:20b] *** -[UIView initWithNibName:bundle:]: unrecognized selector sent to instance 0x3ca4fa0
2010-05-20 10:59:50.406 X[19620:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView initWithNibName:bundle:]: unrecognized selector sent to instance 0x3ca4fa0
'
So any ideas anyone?
Many thanks,
Fiona
//
// ContactDetailViewController.m
// X
//
// Created by Fiona on 19/05/2010.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ContactDetailViewController.h"
#import "DisplayInfoViewController.h"
#import "ActionViewController.h"
#define SectionHeaderHeigth 200
#implementation ContactDetailViewController
#synthesize name;
#synthesize date;
#synthesize headerView;
#synthesize nextAction;
#synthesize nameLabel;
#synthesize usernameLabel;
#synthesize nextActionTextField;
#synthesize dateLabel;
#synthesize notesTableView;
#synthesize contactInfoButton;
#synthesize backgroundInfoButton;
#synthesize actionDoneButton;
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int numOfRows;
NSLog(#"section: %d", section);
switch (section){
case 0:
numOfRows = 0;
break;
case 1:
numOfRows = 3;
break;
default:
break;
}
return numOfRows;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 0){
headerView = [[UIView alloc] initWithNibName:#"ContactHeaderDetail" bundle:nil];
// headerView = [[UIView alloc] initWithNibName:#"ContactHeaderDetail" bundle:nil];
return headerView;
}else{
return nil;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return SectionHeaderHeigth;
}
// 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];
}
// Set up the cell...
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:#"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [anotherViewController release];
}
/*
// 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:YES];
}
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;
}
*/
-(IBAction)displayContactInfo:(id)sender{
DisplayInfoViewController *divc = [[DisplayInfoViewController alloc] init];
divc.textView = self.nextAction;
divc.title = #"Contact Info";
[self.navigationController pushViewController:divc animated:YES];
[divc release];
}
-(IBAction)displayBackgroundInfo:(id)sender{
DisplayInfoViewController *divc = [[DisplayInfoViewController alloc] init];
divc.textView = self.nextAction;
divc.title = #"Background Info";
[self.navigationController pushViewController:divc animated:YES];
[divc release];
}
-(IBAction)actionDone:(id)sender{
ActionViewController *avc = [[ActionViewController alloc] init];
avc.title = #"Action";
avc.nextAction = self.nextAction;
[self.navigationController pushViewController:avc animated:YES];
[avc release];
}
- (void)dealloc {
[name release];
[date release];
[nextAction release];
[nameLabel release];
[usernameLabel release];
[nextActionTextField release];
[dateLabel release];
[notesTableView release];
[contactInfoButton release];
[backgroundInfoButton release];
[actionDoneButton release];
[headerView release];
[super dealloc];
}
#end
headerView = [[UIView alloc] initWithNibName:#"ContactHeaderDetail" bundle:nil];
UIView's don't have XIB, or initWithNibName functions.
Do you mean to make a UIViewController ?
Related
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am creating a simple RSS application and I am not that good in Objective-c. The application will always build successful and there is no errors or warnings, in the UITableView which reads the RSS, whenever i press the cells it will terminate and in the main.m this thread will come "Thread 1: signal SIGABRT" in this line:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
The information of my app:
The app is created by Xcode version: 4.3.1
The app was created from the "Master-Detail Application" template for iPhone and on a MacBook.
The debugger I am using is LLDB and my iPhone simulator is 5.1
I am using Storyboard
Here is the Main.m:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
The AppDelegate.h is:
#import <UIKit/UIKit.h>
#interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#end
My AppDelegate.m is:
#import "AppDelegate.h"
#import "AppDelegate.h"
#import "MasterViewController.h"
#implementation AppDelegate
#synthesize window;
#synthesize navigationController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate
}
#pragma mark -
#pragma mark Memory management
- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}
#end
This is the console message:
2012-03-17 17:32:29.498 Rahnavard[1862:12e03] fetch rss
2012-03-17 17:33:01.212 Rahnavard[1862:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/hassantavari/Library/Application Support/iPhone Simulator/5.1/Applications/48090189-E17C-40CF-9BF1-ACA18FC0B02B/Rahnavard.app> (loaded)' with name 'DetailViewController''
*** First throw call stack:
(0x16e4022 0x1875cd6 0x168ca48 0x168c9b9 0x366638 0x20c1fc 0x20c779 0x20c99b 0x20cd11 0x21e8fd 0x21eaef 0x21edbb 0x21f85f 0x21fe06 0x21fa24 0x393c 0x1d65c5 0x1d67fa 0xa6b85d 0x16b8936 0x16b83d7 0x161b790 0x161ad84 0x161ac9b 0x15cd7d8 0x15cd88a 0x145626 0x26a2 0x2615)
terminate called throwing an exception(lldb)
Here is were the fetch RSS:
-(void)fetchRss
{
NSLog(#"fetch rss");
NSData* xmlData = [[NSMutableData alloc] initWithContentsOfURL:[NSURL URLWithString: kRSSUrl] ];
NSError *error;
GDataXMLDocument* doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&error];
if (doc != nil) {
self.loaded = YES;
GDataXMLNode* title = [[[doc rootElement] nodesForXPath:#"channel/title" error:&error] objectAtIndex:0];
[self.delegate updatedFeedTitle: [title stringValue] ];
NSArray* items = [[doc rootElement] nodesForXPath:#"channel/item" error:&error];
NSMutableArray* rssItems = [NSMutableArray arrayWithCapacity:[items count] ];
for (GDataXMLElement* xmlItem in items) {
[rssItems addObject: [self getItemFromXmlElement:xmlItem] ];
}
[self.delegate performSelectorOnMainThread:#selector(updatedFeedWithRSS:) withObject:rssItems waitUntilDone:YES];
} else {
[self.delegate performSelectorOnMainThread:#selector(failedFeedUpdateWithError:) withObject:error waitUntilDone:YES];
}
[doc autorelease];
[xmlData release];
}
MasterViewController.h:
#import <UIKit/UIKit.h>
#import "RSSLoader.h"
#import "DetailViewController.h"
#interface MasterViewController : UITableViewController<RSSLoaderDelegate> {
RSSLoader* rss;
NSMutableArray* rssItems;
}
#end
MasterViewController.m:
#import "MasterViewController.h"
#import "DetailViewController.h"
#implementation MasterViewController
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = #"RAHNAVARD";
self.navigationItem.prompt = #"LATEST NEWS";
rssItems = nil;
rss = nil;
self.tableView.backgroundColor = [UIColor whiteColor];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.tableView setIndicatorStyle:UIScrollViewIndicatorStyleWhite];
//self.tableView.tableHeaderView = [[TableHeaderView alloc] initWithText:#"fetching rss feed"];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (rss==nil) {
rss = [[RSSLoader alloc] init];
rss.delegate = self;
[rss load];
}
}
/*
- (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);
}
*/
#pragma mark -
#pragma mark Table view data source
// 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 {
if (rss.loaded == YES) {
return [rssItems count]*2;
} else {
return 1;
}
}
- (UITableViewCell *)getLoadingTableCellWithTableView:(UITableView *)tableView
{
static NSString *LoadingCellIdentifier = #"LoadingCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LoadingCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:LoadingCellIdentifier] autorelease];
}
cell.textLabel.text = #"Loading...";
UIActivityIndicatorView* activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activity startAnimating];
[cell setAccessoryView: activity];
[activity release];
return cell;
}
- (UITableViewCell *)getTextCellWithTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath {
static NSString *TextCellIdentifier = #"TextCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TextCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:TextCellIdentifier] autorelease];
}
NSDictionary* item = [rssItems objectAtIndex: (indexPath.row-1)/2];
//article preview
cell.textLabel.font = [UIFont systemFontOfSize:11];
cell.textLabel.numberOfLines = 3;
cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
CGRect f = cell.textLabel.frame;
[cell.textLabel setFrame: CGRectMake(f.origin.x+15, f.origin.y, f.size.width-15, f.size.height)];
cell.textLabel.text = [item objectForKey:#"description"];
return cell;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (rss.loaded == NO) {
return [self getLoadingTableCellWithTableView:tableView];
}
if (indexPath.row % 2 == 1) {
return [self getTextCellWithTableView:tableView atIndexPath:indexPath];
}
static NSString *CellIdentifier = #"TitleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
NSDictionary* item = [rssItems objectAtIndex: indexPath.row/2];
cell.textLabel.text = [item objectForKey:#"title"];
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 -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
//DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
detailViewController.item = [rssItems objectAtIndex:floor(indexPath.row/2)];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
#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 {
[rssItems release];
rssItems = nil;
[rss release];
rss = nil;
[super dealloc];
}
#pragma mark -
#pragma mark RSSLoaderDelegate
-(void)updatedFeedWithRSS:(NSMutableArray*)items
{
rssItems = [items retain];
[self.tableView reloadData];
}
-(void)failedFeedUpdateWithError:(NSError *)error
{
//
}
#end
If you want more information just say it to me by answers and I will edit my question and then you will edit your answer.
I would really appreciate you help.
SIGABRT means in general that there is an uncaught exception. There should be more information on the console.
You are trying to load a XIB named DetailViewController, but no such XIB exists or it's not member of your current target.
SIGABRT is, as stated in other answers, a general uncaught exception. You should definitely learn a little bit more about Objective-C. The problem is probably in your UITableViewDelegate method didSelectRowAtIndexPath.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
I can't tell you much more until you show us something of the code where you handle the table data source and delegate methods.
Having trouble implementing the following to look like this:
Design view: http://i53.tinypic.com/2hqe9lk.png
Simulator view: http://i56.tinypic.com/2luw68j.png
It doesn't display the background, textbox, nor the submit button :( All it displays is the table.
What am I doing wrong?
Thanks!!!
Code for the view is as follows;
BooksTableViewController.m
//
// BooksTableViewController.m
// ORBooks
//
// Created by Elisabeth Robson on 6/19/09.
// Copyright 2009 Elisabeth Robson. All rights reserved.
//
#import "BooksTableViewController.h"
#import "BookDetailViewController.h"
#import "ORBooksAppDelegate.h"
#implementation BooksTableViewController
#synthesize booksArray;
#synthesize bookDetailViewController;
#synthesize number;
/*
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if (self = [super initWithStyle:style]) {
}
return self;
}
*/
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: #"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];
[[self navigationItem] setBackBarButtonItem: newBackButton];
[newBackButton release];
NSMutableArray *array = [[NSArray alloc] initWithObjects:#"sub1", #"sub2", nil];
self.booksArray = array;
[array release];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
/*
- (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);
}
*/
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;//[self.booksArray 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] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSUInteger row = [indexPath row];
cell.text = [booksArray objectAtIndex:row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:#"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [anotherViewController release];
NSInteger row = [indexPath row];
if (self.bookDetailViewController == nil) {
BookDetailViewController *aBookDetail = [[BookDetailViewController alloc] initWithNibName:#"BookDetailView" bundle:nil];
self.bookDetailViewController = aBookDetail;
[aBookDetail release];
}
//bookDetailViewController.title = [NSString stringWithFormat:#"%#", [booksArray objectAtIndex:row]];
//ORBooksAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
//[delegate.booksNavController pushViewController:bookDetailViewController animated:YES];
[self.navigationController pushViewController:bookDetailViewController animated:YES];
}
/*
// 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:YES];
}
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;
}
*/
- (void)dealloc {
[bookDetailViewController release];
[super dealloc];
}
#end
BooksTableViewController.h
//
// BooksTableViewController.h
// ORBooks
//
// Created by Elisabeth Robson on 6/19/09.
// Copyright 2009 Elisabeth Robson. All rights reserved.
//
#import <UIKit/UIKit.h>
#class BookDetailViewController;
// don't need to specify the delegate, datasource interfaces; UITableViewController gets those automatically
#interface BooksTableViewController : UITableViewController {
IBOutlet UITextField *number;
IBOutlet UITableView *booksTableView;
NSMutableArray *booksArray;
BookDetailViewController *bookDetailViewController;
}
- (IBAction)submit:(id)sender;
#property (nonatomic, retain) UITextField *number;
#property (nonatomic, retain) NSMutableArray *booksArray;
#property (nonatomic, retain) BookDetailViewController *bookDetailViewController;
#end
You'll have to change the UITableViewController to UIViewController in the header file.
What you are doing is adding everything to the tableview. Instead you'll have to add your tableview to the UIViewController and the same for UITextfield and UIButton.
Rest is fine.
I have a table view that you can add and delete cells. I can enter multiple cells and when i go to the next page and then switch back, all of my entries/ cells are erased. Can any one figure this out? Here is my code:
#implementation FacePlatesViewController
#synthesize woodGrain;
#synthesize nav, array;
#synthesize EditButton;
#synthesize myTableView, image;
#synthesize cell, string1;
#synthesize myDic, cells, defaults;
#synthesize selectedCell, currentChosenFund;
- (void)viewDidLoad {
[super viewDidLoad];
NSString * myFile = [[NSBundle mainBundle]pathForResource:#"cells" ofType:#"plist"];
self.myTableView.backgroundColor = [UIColor clearColor];
cells = [[NSMutableArray alloc]initWithContentsOfFile:myFile];
}
- (void)addObject:(id)anObject
{
if (anObject != nil)
{
[cells addObject:anObject];
}
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.myTableView reloadData];
}
- (IBAction)editButton:(id)sender
{
if (self.editing)
{
[self setEditing:NO animated:YES];
[self.myTableView setEditing:NO animated:YES];
}
else
{
[self setEditing:YES animated:YES];
[self.myTableView setEditing:YES animated:YES];
}
}
- (void)add
{
MyDetailViewController * detail = [[MyDetailViewController alloc]init];
detail.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:detail animated:YES];
[detail.text becomeFirstResponder];
[detail release];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [cells count];
}
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[[self cells] removeObjectAtIndex:[indexPath row]];
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[[self myTableView] deleteRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationFade];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
reuseIdentifier:CellIdentifier] autorelease];
}
//The if block should end here. You should set the cell's label irrespective whether the cell was nil. This is the cause of the issue you are facing.
cell.textLabel.text = [[cells objectAtIndex:indexPath.row] valueForKey:#"name"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FirstFolderViewController * first = [[FirstFolderViewController alloc]init];
first.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:first animated:YES];
[first release];
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath
toIndexPath:(NSIndexPath *)targetIndexPath
{
NSUInteger sourceIndex = [sourceIndexPath row];
NSUInteger targetIndex = [targetIndexPath row];
if (sourceIndex != targetIndex)
{
[[self cells] exchangeObjectAtIndex:sourceIndex
withObjectAtIndex:targetIndex];
}
}
- (void)dealloc
{
[woodGrain release];
[myTableView release];
[EditButton release];
[nav release];
[cells release];
[myTableView release];
[myDic release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[self setWoodGrain:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
Thanks :D
Actually even unloading of the view will be enough to throw away the cells. Try this in your viewDidLoad:
if(!cells) {
NSString * myFile = [[NSBundle mainBundle]pathForResource:#"cells" ofType:#"plist"];
self.myTableView.backgroundColor = [UIColor clearColor];
cells = [[NSMutableArray alloc]initWithContentsOfFile:myFile];
}
(this way you won't be rereading the array every time the view is loaded).
And if you want the added cells to persist between app restarts, you do need to save them somewhere. You can't change the files in the main bundle, but you can write your own file into the Caches folder, which you can get via:
[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
Write your file into that folder and read the cells from there instead of the main bundle. If you have some pre-defined cells in the main bundle file, you can check if the file in the Caches folder exists when the app starts, and if not, copy the bundle's file into the Caches folder.
Edit: if you do presentModalViewController to get back from the another page, you'll get a fresh copy of FacePlatesViewController, which obviously loads the default cells from the file.
Instead, you should add a "delegate" property to your FirstFolderViewController:
#property(nonatomic, assign) id delegate; //yes, assign, not retain
then when presenting FirstFolderViewController do:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FirstFolderViewController * first = [[FirstFolderViewController alloc]init];
first.delegate = self;
first.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:first animated:YES];
[first release];
}
Then add a method to FacePlatesViewController:
- (void) onDoneWithFirstFolderViewController //you can come up with a better name
{
[self dismissModalViewControllerAnimated:YES];
}
and in your FirstFolderViewController, when you are ready to close it, do:
if([delegate respondsToSelector:#selector(onDoneWithFirstFolderViewController)])
[delegate onDoneWithFirstFolderViewController];
Ironically, if you had implemented the cell persistence in a file, this issue might have been unnoticed (because each new FacePlatesViewController would load an up-to-date cell list), but you would have had a memory leak each time you went between pages.
To me, the problem seems to be related to your code in ViewWillAppear: Have you ensured that your cells array is fine when you call [self.myTableView reloadData]; ?
Also, I noticed myTableView. Are you subclassing UITableViewController or implementing table delegates? If you are subclassing, the table view reference is named tableView.
HTH,
Akshay
My application get crashing. It's loading data of all the cities, and when I click its displaying my detailed view controller.
When I am getting back from my controller, and selecting another city my application get crashed.
I am pasting my code.
#import "CityNameViewController.h"
#import "Cities.h"
#import "XMLParser.h"
#import "PartyTemperature_AppDelegate.h"
#import "CityEventViewController.h"
#implementation CityNameViewController
//#synthesize aCities;
#synthesize appDelegate;
#synthesize currentIndex;
#synthesize aCities;
/*
// 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 {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title=#"Cities";
appDelegate=(PartyTemperature_AppDelegate *)[[UIApplication sharedApplication]delegate];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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 [appDelegate.cityListArray count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 95.0f;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.textColor = [[[UIColor alloc] initWithRed:0.2 green:0.2 blue:0.6 alpha:1] autorelease];
cell.detailTextLabel.textColor = [UIColor blackColor];
cell.detailTextLabel.font=[UIFont systemFontOfSize:10];
if (indexPath.row %2 == 1) {
cell.backgroundColor = [[[UIColor alloc] initWithRed:0.87f green:0.87f blue:0.87f alpha:1.0f] autorelease];
} else {
cell.backgroundColor = [[[UIColor alloc] initWithRed:0.97f green:0.97f blue:0.97f alpha:1.0f] autorelease];
}
}
// 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:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle= UITableViewCellSelectionStyleBlue;
// cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.backgroundColor=[UIColor blueColor];
}
// aCities=[appDelegate.cityListArray objectAtIndex:indexPath.row];
// cell.textLabel.text=aCities.city_Name;
cell.textLabel.text=[[appDelegate.cityListArray objectAtIndex:indexPath.row]city_Name];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//http://compliantbox.com/party_temperature/citysearch.php?city=Amsterdam&latitude=52.366125&longitude=4.899171
NSString *url;
aCities=[appDelegate.cityListArray objectAtIndex:indexPath.row];
if ([appDelegate.cityListArray count]>0){
url=#"http://compliantbox.com/party_temperature/citysearch.php?city=";
url=[url stringByAppendingString:aCities.city_Name];
url=[url stringByAppendingString:#"&latitude=52.366125&longitude=4.899171"];
NSLog(#"url value is %#",url);
[self parseCityName:[[NSURL alloc]initWithString:url]];
}
}
-(void)parseCityName:(NSURL *)url{
NSXMLParser *xmlParser=[[NSXMLParser alloc]initWithContentsOfURL:url];
XMLParser *parser=[[XMLParser alloc] initXMLParser];
[xmlParser setDelegate:parser];
BOOL success;
success=[xmlParser parse];
if (success) {
NSLog(#"Sucessfully parsed");
CityEventViewController *cityEventViewController=[[CityEventViewController alloc]initWithNibName:#"CityEventViewController" bundle:nil];
cityEventViewController.index=currentIndex;
[self.navigationController pushViewController:cityEventViewController animated:YES];
[cityEventViewController release];
cityEventViewController=nil;
}
else {
NSLog(#"Try it Idoit");
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Alert!" message:#"Event Not In Radius" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (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 {
[aCities release];
[super dealloc];
}
#end
And the error is
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 1 beyond bounds for empty array'
*** Call stack at first throw:
The Array cityListArray seems to be empty when you return to the tableview. If you modify cityListArray from elsewhere I'd suggest to call [tableView reloadData] in viewWillAppear.
yeah its a good idea to reload the table data once its display again, that way you can be sure the data is correct. One more thing i would like to point out is if you have city names with characters like space or quotes its always a good idea to escape the url string, if not you might get unexpected results.
In my application
It do have tableview... with two rows.
Date.
City.
When selected Date ...i load EventViewController view which working well and good...
when getting back to my tableview and selected City my app get crashed
I do not see any thing in my console. its not showing any message.
What to do...
here is the code....
The For implementation......
but my app get crashed...
#import "SearchViewController.h"
#import "SearchDetailViewController.h"
#import "EventViewController.h"
#implementation SearchViewController
#synthesize searchListArray;
/*
// 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 {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *barButton=[[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem=barButton;
[barButton release];
searchListArray =[[NSMutableArray alloc]init];
[searchListArray addObject:#"City"];
[searchListArray addObject:#"Populair"];
[searchListArray addObject:#"Date"];
}
- (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 [searchListArray 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:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle= UITableViewCellSelectionStyleBlue;
// cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.backgroundColor=[UIColor blueColor];
cell.textLabel.text=[searchListArray objectAtIndex:indexPath.row];
switch (indexPath.row) {
case 0:
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
break;
case 2:
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
break;
default:
break;
}
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case 0:
NSLog(#"searchdetailedview");
SearchDetailViewController *searchDetailViewController = [[SearchDetailViewController alloc] initWithNibName:#"SearchDetailViewController" bundle:nil];
[self.navigationController pushViewController:searchDetailViewController animated:YES];
// self.navigationItem.title = #"Back";
[searchDetailViewController release];
searchDetailViewController=nil;
break;
case 2:
NSLog(#"eventviewController");
EventViewController *eventViewController=[[EventViewController alloc]initWithNibName:#"EventViewController" bundle:nil];
[self.navigationController pushViewController:eventViewController animated:YES];
[eventViewController release];
eventViewController=nil;
break;
default:
break;
}
}
/*
// 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 {
[searchListArray release];
[super dealloc];
}
EventViewController
#import "EventViewController.h"
#implementation EventViewController
#synthesize eventsList;
#synthesize eventStore;
#synthesize defaultCalendar;
#synthesize detailViewController;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.title=#"Event List";
self.eventStore=[[EKEventStore alloc]init];
self.eventsList=[[NSMutableArray alloc]initWithArray:0];
self.defaultCalendar=[self.eventStore defaultCalendarForNewEvents];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemAdd target:self action:#selector(addEvent:)];
self.navigationItem.rightBarButtonItem = addButtonItem;
[addButtonItem release];
self.navigationController.delegate = self;
[self.eventsList addObjectsFromArray:[self fetchEventsForToday]];
[self.tableView reloadData];
}
- (IBAction) addEvent:(id)sender{
EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
// set the addController's event store to the current event store.
addController.eventStore = self.eventStore;
// present EventsAddViewController as a modal view controller
[self presentModalViewController:addController animated:YES];
addController.editViewDelegate = self;
[addController release];
}
- (NSArray *) fetchEventsForToday{
NSDate *startDate = [NSDate date];
// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:86400];
// Create the predicate. Pass it the default calendar.
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate
calendars:calendarArray];
// Fetch all events that match the predicate.
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
return events;
}
- (void)viewWillAppear:(BOOL)animated {
// [super viewWillAppear:animated];
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:NO];
}
/*
- (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);
}
#pragma mark -
#pragma mark Table view data source
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// // Return the number of sections.
// // return <#number of sections#>;
//}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [eventsList count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCellAccessoryType editableCellAccessoryType =UITableViewCellAccessoryDisclosureIndicator;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.accessoryType=editableCellAccessoryType;
cell.textLabel.text=[[self.eventsList objectAtIndex:indexPath.row]title];
// Configure the cell...
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 -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// Upon selecting an event, create an EKEventViewController to display the event.
self.detailViewController = [[EKEventViewController alloc] initWithNibName:nil bundle:nil];
detailViewController.event = [self.eventsList objectAtIndex:indexPath.row];
// Allow event editing.
detailViewController.allowsEditing = YES;
// Push detailViewController onto the navigation controller stack
// If the underlying event gets deleted, detailViewController will remove itself from
// the stack and clear its event property.
[self.navigationController pushViewController:detailViewController animated:YES];
}
#pragma mark -
#pragma mark Navigation Controller delegate
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
if (viewController == self && self.detailViewController.event.title == NULL) {
[self.eventsList removeObject:self.detailViewController.event];
[self.tableView reloadData];
}
}
- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action{
NSError *error=nil;
EKEvent *thisEvent=controller.event;
switch (action) {
case EKEventEditViewActionCanceled:
break;
case EKEventEditViewActionSaved:
if (self.defaultCalendar ==thisEvent.calendar) {
[self.eventsList addObject:thisEvent];
}
[controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&error];
[self.tableView reloadData];
break;
case EKEventEditViewActionDeleted:
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList removeObject:thisEvent];
}
[controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error];
[self.tableView reloadData];
break;
default:
break;
}
[controller dismissModalViewControllerAnimated:YES];
}
- (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller{
EKCalendar *calendarForEdit=self.defaultCalendar;
return calendarForEdit;
}
#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;
self.eventsList = nil;
[self.detailViewController release];
}
- (void)dealloc {
[super dealloc];
}
This is what i did.... Help me out.
#thanks in advance.
Please do the following steps:
1) Press Build and Debug (Build -> Build and Debug - Breakpoints on)
2) Open your Debugger
3) Create the crash
4) Now, go to the debugger and search for a black item on the left side
5) Press this item and you'll find where the app is crashing
If you have done this, please write where your application crashs - this will be much easier. And maybe, you'll find the error.
I think your problem could be the self.navigationController.delegate = self; in -[EventViewController viewDidLoad]. When you hit the back button, the EventViewController is released, but the navigationController still thinks it is its delegate. Therefore, when it asks if it is OK to open the next view controller, it is calling methods on a released object and causing a crash.