Created
December 20, 2011 11:53
-
-
Save anonymous/1501328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// class of form with the button | |
#import <UIKit/UIKit.h> | |
@class Favorites; | |
@interface Info : UIViewController | |
{ | |
NSMutableArray *favGifts; | |
NSString *justAstring; | |
} | |
@property (nonatomic, retain) NSMutableArray *favGifts; | |
@property (nonatomic, retain) NSString *justAstring; | |
- (IBAction)save:(id)sender; | |
-(NSString *)pathOfFile; | |
@end | |
//Info.m | |
#import "Info.h" | |
@implementation Info | |
@synthesize ADFbutton; | |
@synthesize justAstring; | |
@synthesize favGifts; | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | |
{ | |
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |
if (self) { | |
// Custom initialization | |
} | |
return self; | |
} | |
- (NSString *)pathOfFile { | |
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentFolder = [path objectAtIndex:0]; | |
return [documentFolder stringByAppendingFormat:@"myFile.plist"]; | |
} | |
- (IBAction)save:(id)sende{ | |
NSString *m = self.navigationItem.title; | |
favGifts = [[NSMutableArray alloc]init]; | |
[favGifts addObject:m]; | |
[favGifts writeToFile:[self pathOfFile] atomically:YES]; | |
justAstring = self.pathOfFile; | |
NSLog(@"%@", justAstring); | |
} | |
//And this is class on the second tab with the tableview inside: | |
#import <UIKit/UIKit.h> | |
@class Info; | |
@interface Favorites : UIViewController | |
<UITableViewDataSource,UITableViewDelegate>{ | |
UITableView *myTableView; | |
NSString *name; | |
Info *info; | |
} | |
@property (retain, nonatomic) IBOutlet UITableView *myTableView; | |
@property (nonatomic,retain) NSString *name; | |
@property (nonatomic, retain) Info *info; | |
@end | |
// .m | |
#import "Favorites.h" | |
#import "Info.h" | |
NSMutableArray *array; | |
@implementation NewFavGifts | |
@synthesize myTableView; | |
@synthesize giftInfo; | |
@synthesize name; | |
- (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) viewWillAppear:(BOOL)animated{ | |
if ([[NSFileManager defaultManager]fileExistsAtPath:@"myFile.plist"]) { | |
array = [[NSMutableArray alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"plist"]]; | |
} | |
NSLog(@"Array Count %d", [array count]); | |
[myTableView reloadData]; | |
} | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view from its nib. | |
} | |
- (void)viewDidUnload | |
{ | |
[self setMyTableView: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); | |
} | |
- (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 [array count]; | |
} | |
- (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]; | |
} | |
// Configure the cell... | |
NSString *cellValue = [array objectAtIndex:indexPath.row]; | |
cell.textLabel.text = cellValue; | |
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; | |
return cell; | |
} | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { | |
return 75; | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment