Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-26-2012, 10:34 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 25
theshay is on a distinguished road
Exclamation Display contents of directory in UITableView

I have this code:
Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    listOfItems = [[NSMutableArray alloc] init];
    NSFileManager *filemgr;
    NSString *currentpath;
    NSArray *filelist;
    int count;
    int i;
    
    filemgr = [NSFileManager defaultManager];
    
    filelist = [filemgr directoryContentsAtPath: @"/tmp"];
    
    count = [filelist count];
    
    for (i = 0; i < count; i++)[listOfItems addObject:[filelist objectAtIndex: i]];
}

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


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return[listOfItems 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...
	NSString *cellValue =[listOfItems objectAtIndex:indexPath.row];
	cell.text = cellValue;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	//Get the selected country
}

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
	
	//return UITableViewCellAccessoryDetailDisclosureButton;
	return UITableViewCellAccessoryDisclosureIndicator;
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
	
	[self tableView:tableView didSelectRowAtIndexPath:indexPath];
}
but app crashed with this log:
Quote:
[Switching to process 810 thread 0x10103]
Current language: auto; currently objective-c
(gdb)
what i do not correctly?
theshay is offline   Reply With Quote
Old 01-26-2012, 11:33 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: India
Posts: 4
KushIP is on a distinguished road
Default

Quote:
Originally Posted by theshay View Post
I have this code:
Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    listOfItems = [[NSMutableArray alloc] init];
    NSFileManager *filemgr;
    NSString *currentpath;
    NSArray *filelist;
    int count;
    int i;
    
    filemgr = [NSFileManager defaultManager];
    
    filelist = [filemgr directoryContentsAtPath: @"/tmp"];
    
    count = [filelist count];
    
    for (i = 0; i < count; i++)[listOfItems addObject:[filelist objectAtIndex: i]];
}

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


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return[listOfItems 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...
	NSString *cellValue =[listOfItems objectAtIndex:indexPath.row];
	cell.text = cellValue;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	//Get the selected country
}

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
	
	//return UITableViewCellAccessoryDetailDisclosureButton;
	return UITableViewCellAccessoryDisclosureIndicator;
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
	
	[self tableView:tableView didSelectRowAtIndexPath:indexPath];
}
but app crashed with this log:


what i do not correctly?
directoryContentsAtPath is deprecated, may be you should start by changing it to contentsOfDirectoryAtPath:error:
KushIP is offline   Reply With Quote
Old 01-27-2012, 10:33 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 25
theshay is on a distinguished road
Exclamation

Quote:
Originally Posted by KushIP View Post
directoryContentsAtPath is deprecated, may be you should start by changing it to contentsOfDirectoryAtPath:error:
Thanks you!

Still ERROR:

Quote:
[Switching to process 773 thread 0x10103]
Current language: auto; currently objective-c
(gdb)
with code:
Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    listOfItems = [[NSMutableArray alloc] init];
    
    filemgr = [NSFileManager defaultManager];
    
    filelist = [filemgr contentsOfDirectoryAtPath:@"/Users/Shay" error:nil];
    
    count = [filelist count];
    
    for (i = 0; i < count; i++) {
        NSLog(@"%@", [filelist objectAtIndex: i]);
        mover = [NSString stringWithFormat:@"%@", [filelist objectAtIndex: i]]; [listOfItems addObject:mover];
    }
    }

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


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return[listOfItems 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...
	NSString *cellValue =[listOfItems objectAtIndex:indexPath.row];
	cell.text = cellValue;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	//Get the selected country
}

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
	
	//return UITableViewCellAccessoryDetailDisclosureButton;
	return UITableViewCellAccessoryDisclosureIndicator;
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
	
	[self tableView:tableView didSelectRowAtIndexPath:indexPath];
}
whats wrong? it write content of library, and crashed.

Last edited by theshay; 01-27-2012 at 10:45 PM.
theshay is offline   Reply With Quote
Old 01-28-2012, 07:46 AM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by theshay View Post
Thanks you!

Still ERROR:



with code:
Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    listOfItems = [[NSMutableArray alloc] init];
    
    filemgr = [NSFileManager defaultManager];
    
    filelist = [filemgr contentsOfDirectoryAtPath:@"/Users/Shay" error:nil];
    
    count = [filelist count];
    
    for (i = 0; i < count; i++) {
        NSLog(@"%@", [filelist objectAtIndex: i]);
        mover = [NSString stringWithFormat:@"%@", [filelist objectAtIndex: i]]; [listOfItems addObject:mover];
    }
    }

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


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return[listOfItems 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...
	NSString *cellValue =[listOfItems objectAtIndex:indexPath.row];
	cell.text = cellValue;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	//Get the selected country
}

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
	
	//return UITableViewCellAccessoryDetailDisclosureButton;
	return UITableViewCellAccessoryDisclosureIndicator;
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
	
	[self tableView:tableView didSelectRowAtIndexPath:indexPath];
}
whats wrong? it write content of library, and crashed.


Your code is full of all kinds of problems, but at a glance, I don't see anything that would cause a crash. What line is crashing, and what is the full error message you're getting? You didn't provide the full crash message, so I can't tell what's going wrong.


Edit: Your viewDidLoad method is a mess. Here is a marked up copy:


Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    //make sure you release listOfItems in your viewDidUnload method
    listOfItems = [[NSMutableArray alloc] init];
    
    filemgr = [NSFileManager defaultManager];
    
    /*
   Since you copy every item in filelist to listOfItems, why don't you just use
   listOfItems =  [[filemgr contentsOfDirectoryAtPath:@"/Users/Shay" error:nil] retain];
   ---Done---
  
   Next problem: You don't have access to the users directory on iOS. This code
   will only work on the simulator.
   */
    filelist = [filemgr contentsOfDirectoryAtPath:@"/Users/Shay" error:nil];
    
    count = [filelist count];
    /*
    If you're going to loop through the array of filenames, use
    for (mover in filelist)
    */
    for (i = 0; i < count; i++) {
        NSLog(@"%@", [filelist objectAtIndex: i]);
/*
Don't put multiple statements on the same line. It makes it hard to read. 

There's no point in the code [NSString stringWithFormat:@"%@", [filelist objectAtIndex: i]]. All 
[NSString stringWithFormat: @"%@", someString] does is make an un-needed copy of someString in a very 
inefficient way.
*/
        mover = [NSString stringWithFormat:@"%@", [filelist objectAtIndex: i]];[listOfItems addObject:mover];
    }
}
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 01-28-2012 at 08:13 AM.
Duncan C is offline   Reply With Quote
Old 01-28-2012, 09:15 AM   #5 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 25
theshay is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Your code is full of all kinds of problems, but at a glance, I don't see anything that would cause a crash. What line is crashing, and what is the full error message you're getting? You didn't provide the full crash message, so I can't tell what's going wrong.


Edit: Your viewDidLoad method is a mess. Here is a marked up copy:


Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    //make sure you release listOfItems in your viewDidUnload method
    listOfItems = [[NSMutableArray alloc] init];
    
    filemgr = [NSFileManager defaultManager];
    
    /*
   Since you copy every item in filelist to listOfItems, why don't you just use
   listOfItems =  [[filemgr contentsOfDirectoryAtPath:@"/Users/Shay" error:nil] retain];
   ---Done---
  
   Next problem: You don't have access to the users directory on iOS. This code
   will only work on the simulator.
   */
    filelist = [filemgr contentsOfDirectoryAtPath:@"/Users/Shay" error:nil];
    
    count = [filelist count];
    /*
    If you're going to loop through the array of filenames, use
    for (mover in filelist)
    */
    for (i = 0; i < count; i++) {
        NSLog(@"%@", [filelist objectAtIndex: i]);
/*
Don't put multiple statements on the same line. It makes it hard to read. 

There's no point in the code [NSString stringWithFormat:@"%@", [filelist objectAtIndex: i]]. All 
[NSString stringWithFormat: @"%@", someString] does is make an un-needed copy of someString in a very 
inefficient way.
*/
        mover = [NSString stringWithFormat:@"%@", [filelist objectAtIndex: i]];[listOfItems addObject:mover];
    }
}
still crashed. this log:

Code:
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov  3 21:59:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 5452.
[Switching to process 5452 thread 0x12203]
2012-01-28 19:12:24.943 TheWhiteApps[5452:10103] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <DownloadViewController: 0x6e81560>.  Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior.  This method will no longer be called in a future release.
2012-01-28 19:12:24.963 TheWhiteApps[5452:10103] .adobe
2012-01-28 19:12:24.964 TheWhiteApps[5452:10103] .android
2012-01-28 19:12:24.965 TheWhiteApps[5452:10103] .bash_history
2012-01-28 19:12:24.965 TheWhiteApps[5452:10103] .CFUserTextEncoding
2012-01-28 19:12:24.966 TheWhiteApps[5452:10103] .config
2012-01-28 19:12:24.967 TheWhiteApps[5452:10103] .DS_Store
2012-01-28 19:12:24.967 TheWhiteApps[5452:10103] .filezilla
2012-01-28 19:12:24.968 TheWhiteApps[5452:10103] .fontconfig
2012-01-28 19:12:24.969 TheWhiteApps[5452:10103] .gdb_history
2012-01-28 19:12:24.969 TheWhiteApps[5452:10103] .local
2012-01-28 19:12:24.970 TheWhiteApps[5452:10103] .serverauth.1752
2012-01-28 19:12:24.970 TheWhiteApps[5452:10103] .serverauth.1979
2012-01-28 19:12:24.971 TheWhiteApps[5452:10103] .serverauth.292
2012-01-28 19:12:24.972 TheWhiteApps[5452:10103] .serverauth.313
2012-01-28 19:12:24.972 TheWhiteApps[5452:10103] .serverauth.5798
2012-01-28 19:12:24.973 TheWhiteApps[5452:10103] .ssh
2012-01-28 19:12:24.973 TheWhiteApps[5452:10103] .subversion
2012-01-28 19:12:24.974 TheWhiteApps[5452:10103] .Trash
2012-01-28 19:12:24.976 TheWhiteApps[5452:10103] .Xauthority
2012-01-28 19:12:24.993 TheWhiteApps[5452:10103] .Xcode
2012-01-28 19:12:24.994 TheWhiteApps[5452:10103] Applications
2012-01-28 19:12:24.998 TheWhiteApps[5452:10103] DEBIAN
2012-01-28 19:12:24.999 TheWhiteApps[5452:10103] Desktop
2012-01-28 19:12:25.000 TheWhiteApps[5452:10103] Documents
2012-01-28 19:12:25.000 TheWhiteApps[5452:10103] Downloads
2012-01-28 19:12:25.001 TheWhiteApps[5452:10103] Library
2012-01-28 19:12:25.001 TheWhiteApps[5452:10103] Mac OS X Install DVD.dmg
2012-01-28 19:12:25.002 TheWhiteApps[5452:10103] Movies
2012-01-28 19:12:25.002 TheWhiteApps[5452:10103] Music
2012-01-28 19:12:25.003 TheWhiteApps[5452:10103] Packages
2012-01-28 19:12:25.003 TheWhiteApps[5452:10103] Packages.bz2
2012-01-28 19:12:25.004 TheWhiteApps[5452:10103] Pictures
2012-01-28 19:12:25.004 TheWhiteApps[5452:10103] Public
2012-01-28 19:12:25.005 TheWhiteApps[5452:10103] Send Registration
2012-01-28 19:12:25.005 TheWhiteApps[5452:10103] VirtualBox VMs
2012-01-28 19:12:25.006 TheWhiteApps[5452:10103] Wine Files
[Switching to process 5452 thread 0x10103]
Current language:  auto; currently objective-c
(gdb)
(I added this code
Quote:
[listOfItems addObject:mover];

Last edited by theshay; 01-28-2012 at 09:18 AM.
theshay is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 403
9 members and 394 guests
Atatator, condor304, FrankWeller, MAMN84, mraalex, n00b, PowerGoofy, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:57 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0