- (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];
}
}
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.
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)