I just create a simple UITableView in the UIViewController.
.h
#import <UIKit/UIKit.h>
#interface RootController : UIViewController <UITableViewDataSource>
{
NSMutableArray *_tableData;
UITableView *_tableView;
}
#end
.m
#import "RootController.h"
#implementation RootController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
if (!_tableData) {
_tableData = [[NSMutableArray alloc] initWithCapacity:20];
for (int i = 0; i < 50; i++) {
[_tableData addObject:[NSString stringWithFormat:#"%d", i]];
}
}
}
return self;
}
- (void)dealloc
{
[_tableView release];
[_tableData release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view = view;
[view release];
self.view.backgroundColor = [UIColor whiteColor];
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
_tableView.dataSource = self;
}
[self.view addSubview:_tableView];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"TableViewCellIdentifier";
UITableViewCell *cell = nil;
cell = [_tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
}
cell.textLabel.text = [_tableData objectAtIndex:indexPath.row];
return cell;
}
#end
I used instruments to detect memory leak for this, when I scrolled the UITableView, memory
leak occurred.
I use Xcode 4.3.1 and iOS5.1 (iPod touch4).
Someone had this problem?
If you look at the 'responsible library' column, you can see that the culprit is not your code. The leaks are small, you can safely ignore them.
Here is a similar question: WebView: libdispatch leaks in an ARC-enabled app
Related
I'm trying to create a UITableView in a UIViewController (I'd use UITableViewController but I want the UITableView to only use half of the screen space) that will create a new custom cell every time I press a button, and display the current time in that cell and the time since the last time I pressed the button (so the time in this cell minus the time in the cell above it).
The problem is, when I press the button, either nothing happens or, if I don't initialise the property I created for the UITableView, a blank cell appears.
My cell has 3 UILabel's in it, inOut, entryTime and delta, and the IBOutlet I created for the UITableView is timeTable. newEntry is the button. I have set my UITableView's datasource and delegate to my UIViewController, have "called" the protocols UITableViewDataSource, UITableViewDelegate on my UIViewController's header. I can't find what's wrong.
here's my code for the UIViewController:
#interface MainViewController ()
#property (strong, nonatomic) Brain *brain;
#end
#implementation MainViewController{
#private
NSMutableArray *_entryArray;
NSMutableArray *_timeSinceLastEntryArray;
}
#synthesize brain=_brain;
#synthesize timeTable=_timeTable;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_brain = [[Brain alloc] init];
_entryArray = [[NSMutableArray alloc] init];
_timeSinceLastEntryArray = [[NSMutableArray alloc] init];
_timeTable = [[UITableView alloc] initWithFrame:CGRectZero];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [_entryArray count];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier= #"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (indexPath.row%2==0){
cell.inOut.text = [NSString stringWithFormat:#"Entrada %d", indexPath.row/2 +1];
cell.entryTime.text = [NSString stringWithFormat:#"%#", [_entryArray objectAtIndex:indexPath.row]];
if (indexPath.row==0){
cell.delta.text=#"";
}
else {
cell.delta.text = [_timeSinceLastEntryArray objectAtIndex:indexPath.row];
}
}
else{
cell.inOut.text = [NSString stringWithFormat:#"SaĆda %d", (indexPath.row+1)/2];
cell.entryTime.text = [NSString stringWithFormat:#"%#",[_entryArray objectAtIndex:indexPath.row]];
cell.delta.text = [_timeSinceLastEntryArray objectAtIndex:indexPath.row];
}
return cell;
}
- (IBAction)newEntry:(id)sender {
[_entryArray addObject:[self.brain currentTime]];
NSInteger numberOfEntrys= [_entryArray count];
if (numberOfEntrys >1){
NSString *timeSinceLastEntry = [_brain timeSince:[_entryArray objectAtIndex:(numberOfEntrys-2)]];
[_timeSinceLastEntryArray addObject:timeSinceLastEntry];
}
else {
[_timeSinceLastEntryArray addObject:#"0"];
}
[_timeTable reloadData];
}
#end
and for CustomCell:
#implementation CustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#synthesize inOut=_inOut, entryTime=_entryTime, delta=_delta;
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
_inOut = [[UILabel alloc]init];
_inOut.textAlignment = UITextAlignmentLeft;
_entryTime = [[UILabel alloc]init];
_entryTime.textAlignment = UITextAlignmentLeft;
_delta = [[UILabel alloc]init];
_delta.textAlignment = UITextAlignmentLeft;
[self.contentView addSubview:_entryTime];
[self.contentView addSubview:_inOut];
[self.contentView addSubview:_delta];
}
return self;
}
#end
Thanks for the help :)
I see you put the initialize code in
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
But you create object with
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
and you did not provided the Frame to the view that you created
_inOut = [[UILabel alloc]init];
_entryTime = [[UILabel alloc]init];
_delta = [[UILabel alloc]init];
Hope it helps you
I have a tab based application. On the first tab I have several views one of which is a navigation controller. My goal is to load this list view(working) then goto a detailview on the cell click(not working).
On the cell click I am logging
NSLog(#"%#",self.navigationController);
which is returning a null. I can only assume that I have not done something right with setting up the navigation controller but I do not know what.
on button click the table view is called:
#import "Reviews.h"
#import "XMLParser.h"
#import "Detailed_Review.h"
#implementation Reviews
#synthesize reviewsTableView;
XMLParser *xmlParser;
CGRect dateFrame;
UILabel *dateLabel;
CGRect contentFrame;
UILabel *contentLabel;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[xmlParser reviews] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
Review_Object *currentReview = [[xmlParser reviews] objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
CGRect contentFrame = CGRectMake(10, 2, 265, 30);
UILabel *contentLabel = [[UILabel alloc] initWithFrame:contentFrame];
contentLabel.tag = 0011;
contentLabel.numberOfLines = 2;
contentLabel.font = [UIFont boldSystemFontOfSize:12];
[cell.contentView addSubview:contentLabel];
CGRect reviewFrame = CGRectMake(10, 40, 265, 10);
UILabel *reviewLabel = [[UILabel alloc] initWithFrame:reviewFrame];
reviewLabel.tag = 0012;
reviewLabel.font = [UIFont systemFontOfSize:10];
[cell.contentView addSubview:reviewLabel];
}
UILabel *contentLabel = (UILabel *)[cell.contentView viewWithTag:0011];
contentLabel.text = [currentReview rating];
UILabel *dateLabel = (UILabel *)[cell.contentView viewWithTag:0012];
dateLabel.text = [currentReview review];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 55;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Detailed_Review *dvController = [[Detailed_Review alloc] initWithNibName:#"Detailed_Review" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
NSLog(#"%#",self.navigationController);
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
xmlParser = [[XMLParser alloc] loadXMLByURL:#"http://www.mywebsite.com/api/reviews/xml.php?page=1"];
self.title = #"Reviews";
}
- (void)viewDidUnload
{
[self setReviewsTableView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = 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];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
xib photos:
.h file:
#import <UIKit/UIKit.h>
#import "XMLParser.h"
#import "Review_Object.h"
#interface Reviews : UIViewController
#property (retain, nonatomic) IBOutlet UITableView *reviewsTableView;
#end
You omitted the part where the navigationController is allocated and initialized. Can you add that, including the relevant part from the .h file too?
Either create it with IB or programatically, see https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerPGforiOSLegacy/NavigationControllers/NavigationControllers.html#//apple_ref/doc/uid/TP40011381-CH103-SW27
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.
I created UI for Iphone that has a button and label above tableview. The problem is that data doesn't show in table despite setting it in cellForRowAtIndexPath method.
I get this:
This is my code for controller of third tab. Header:
#import <UIKit/UIKit.h>
#interface ThirdView : UIViewController <UITableViewDelegate,UITableViewDataSource> {
//model
NSMutableArray *podatki;
//view
UITableView *myTableView;
}
#property(nonatomic,retain) NSMutableArray *podatki;
#property(nonatomic,retain) UITableView *myTableView;
-(IBAction)pritisnuGumb:(UIButton *) sender; //
#end
Implementation:
#import "ThirdView.h"
#implementation ThirdView
#synthesize podatki;
#synthesize myTableView;
-(void)viewDidLoad{
myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
myTableView.delegate = self;
myTableView.dataSource = self;
myTableView.autoresizesSubviews = YES;
podatki = [[NSMutableArray alloc] init];
[podatki addObject:#"Sunday"];
[podatki addObject:#"MonDay"];
[podatki addObject:#"TuesDay"];
[super viewDidLoad];
//self.view = myTableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [podatki count];
}
-(IBAction)pritisnuGumb:(UIButton *) sender {
NSLog(#"buca");
}
- (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.textLabel.numberOfLines = 4;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString *naslov = [podatki objectAtIndex:indexPath.row];
cell.textLabel.text = naslov;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"kliknu na vrstico");
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (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.
}
#pragma mark - View lifecycle
- (void)viewDidUnload
{
[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);
}
- (void)dealloc {
[podatki release];
[super dealloc];
}
#end
If i uncomment line "self.view = myTableView;" i get tableview with data but label and button above it disappear (tableview is fullscreen).
What am i doing wrong here?
#Jennis:
I tried your solution and data inside table is now visible but upper part is squeezed like this:
I believe that you can do like
[self.view addSubview:myTableView];
[self.view sendSubviewToBack:myTableView].
hope it helps
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.