send data in another ViewController - objective-c

I need to pass the class PassengerNavi data server Parse give authorized users. And then write the data to the NSString. And how to get data from PFUser I do not know, I really need help developers)
My ViewController.m file:
#import <CloudKit/CloudKit.h>
#import <Parse/Parse.h>
#import "PassengerNavi.h"
#import "ViewController.h"
#import "RegistrationConsole.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)authorizationController:(id)sender {
[PFUser logInWithUsernameInBackground:self.username.text
password:self.password.text block:^(PFUser *user, NSError *error)
{
if (!error) {
PassengerNavi *PassengerViewController = [[PassengerNavi alloc]initWithNibName:#"PassengerNavi" bundle:nil];
[self presentViewController:PassengerViewController animated:YES completion:nil];
} else {
UIAlertView *errorAlertView = [[UIAlertView alloc]initWithTitle:#"British Airways" message:#"Your have Business Class ticket. Please use First Class ticket or contact with British Airways customer center." delegate:nil cancelButtonTitle:#"Close" otherButtonTitles:nil, nil];
[errorAlertView show];
}
}];
}
- (IBAction)registrationController:(id)sender {
RegistrationConsole *RegistrationViewController = [[RegistrationConsole alloc]initWithNibName:#"RegistrationConsole" bundle:nil];
[self presentViewController:RegistrationViewController animated:nil completion:nil];
}
#end
My PassengerNavi.m:
#import "ViewController.h"
#import <Parse/Parse.h>
#interface PassengerNavi ()
#end
#implementation PassengerNavi
- (void)viewDidLoad {
[super viewDidLoad];
[[[[UIApplication sharedApplication] delegate] window] rootViewController];
PFQuery *test = [PFQuery queryWithClassName:#"_User"];
[test whereKey:#"google" equalTo:[PFUser currentUser]];
[test whereKey:#"objectId" equalTo:[NSNumber numberWithInt:1]];
NSArray *arrayofObjectIds = [test findObjects];
PFQuery *query = [PFUser query];
[query whereKey:#"objectId" containedIn:arrayofObjectIds];
NSArray *followingArray = [query findObjects];
NSLog(#"%#",followingArray);
self.clubWorldID = followingArray;
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"ba_fc_wallpaper.jpg"]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)britishDialler:(id)sender {
BACalling *CallerViewController = [[BACalling alloc]initWithNibName:#"BACalling" bundle:nil];
[self presentViewController:CallerViewController animated:YES completion:NULL];
}
- (IBAction)britishMessenger:(id)sender {
BAMessenger *MessengerViewController = [[BAMessenger alloc]initWithNibName:#"BAMessenger" bundle:nil];
[self presentViewController:MessengerViewController animated:YES completion:nil];
}
- (IBAction)personalProfileView:(id)sender {
PersonalProfile *PersonalViewController = [[PersonalProfile alloc]initWithNibName:#"PersonalProfile" bundle:nil];
[self presentViewController:PersonalViewController animated:YES completion:nil];
}
- (IBAction)aboutSoftwareView:(id)sender {
AboutSoftware *AboutViewController = [[AboutSoftware alloc]initWithNibName:#"AboutSoftware" bundle:nil];
[self presentViewController:AboutViewController animated:YES completion:nil];
}
#end

Try this code:
SecondViewController *vc = [[SecondViewController alloc] init];
vc.usernameObjectId = // <-- however you store/produce the value in FirstViewController
After that, push/display/whatever vc.
FYI: It's better to declare an NSString property as:
#property (copy, nonatomic) NSString *...

Related

UITableViewController with UISearchDisplayController not reloading data

I have a ViewController class with an appropriate .XIB file. Here is the ViewController code:
ViewController.h:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface ViewController : UIViewController
{
NSArray *news;
NSMutableData *data;
}
#property (strong, nonatomic) IBOutlet UITableView *mainTableView;
#property (strong, nonatomic) IBOutlet UISearchBar *searchBar;
#property (strong, nonatomic) Results *result;
#end
ViewController.m:
#import "ViewController.h"
#import "Results.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize result, mainTableView, searchBar;
-(id) init
{
self = [super initWithNibName:#"ViewController_iPhone" bundle:nil];
if (self)
{
result = [[Results alloc] init];
mainTableView = [[UITableView alloc] init];
[self.mainTableView setDelegate:self];
}
return self;
}
- (void)viewDidLoad
{
self.title = #"Search";
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
[super viewDidLoad];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString *query = searchBar.text;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://samplesite.com/external/metasearchjson.php?query=%#", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection connectionWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
data = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
{
[data appendData:theData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSArray *responseDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:NULL];
if ([responseDict isKindOfClass:[NSArray class]]) {
news = responseDict;
//[mainTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
[[self mainTableView] reloadData];
NSLog(#"%#", mainTableView);
} else {
NSLog(#"JSON Error.");
}
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:[indexPath row] inSection:0]];
NSString *url = _getString([[news objectAtIndex:[indexPath row]] objectForKey:#"link"]);
[result getURL:url];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[self.navigationController pushViewController:result animated:YES];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:#"Error" message:#"The download could not complete - please make sure you're connected to either 3G or Wi-Fi." delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[errorView show];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (int)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [news count];
}
NSString *_getString(id obj)
{
return [obj isKindOfClass:[NSString class]] ? obj : nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MainCell"];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"MainCell"];
}
cell.detailTextLabel.text = _getString([[news objectAtIndex:indexPath.row] objectForKey:#"metaScore"]);
cell.textLabel.text = _getString([[news objectAtIndex:indexPath.row] objectForKey:#"title"]);
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
My connections are all working, and the code successfully puts the JSON data into the UITableView.
My problem is, the table view isn't reloading!
I have tried to just load it without a UISearchDisplayController, and it works fine. I'm thinking it's some sort of override. Where my TableView reloads data, that just doesn't work. What's also weird is that if you type in something to the search display, the table view is displayed. What am I doing wrong that the Search Bar doesn't reload the data?
In your search display delegate, you need to implement
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
and return YES.
Try make next steps:
In ViewController.h:
add protocols:
#interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
add property:
#property (strong, nonatomic) NSArray* news;
then replace in connectionDidFinishLoading: method news = responseDict; as
self.news = responseDict;
then perform reloadData in main thread:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
...
dispatch_async(dispatch_get_main_queue(), ^{
[[self mainTableView] reloadData];
});
in ViewController.m insert line [self.mainTableView setDataSource: self]; :
-(id) init
{
self = [super initWithNibName:#"ViewController_iPhone" bundle:nil];
if (self)
{
...
[self.mainTableView setDelegate:self];
[self.mainTableView setDataSource: self];
}
return self;
}
hope it helps you.

No known class method for selector 'sharedStore'

Have a singleton class for BNRItemStore, but when I tried to call it, I get the above error which causes an ARC issue. Have commented out the error.
DetailViewController.m
#import "DetailViewController.h"
#import "BNRItem.h"
#import "BNRImageStore.h"
#import "BNRItemStore.h"
#implementation DetailViewController
#synthesize item;
-(id)initForNewItem:(BOOL)isNew
{
self = [super initWithNibName:#"DetailViewController" bundle:nil];
if(self){
if (isNew) {
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(save:)];
[[self navigationItem] setRightBarButtonItem:doneItem];
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:#selector(cancel:)];
[[self navigationItem] setLeftBarButtonItem:cancelItem];
}
}
return self;
}
-(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle
{
#throw [NSException exceptionWithName:#"Wrong initializer"
reason:#"Use initForNewItem:"
userInfo:nil];
return nil;
}
-(void)viewDidLoad
{
[super viewDidLoad];
UIColor *clr = nil;
if ([[UIDevice currentDevice]userInterfaceIdiom]== UIUserInterfaceIdiomPad) {
clr = [UIColor colorWithRed:0.875 green:0.88 blue:0.91 alpha:1];
} else {
clr = [UIColor groupTableViewBackgroundColor];
}
[[self view]setBackgroundColor:clr];
}
- (void)viewDidUnload {
nameField = nil;
serialNumberField = nil;
valueField = nil;
dateLabel = nil;
imageView = nil;
[super viewDidUnload];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[nameField setText:[item itemName]];
[serialNumberField setText:[item serialNumber]];
[valueField setText:[NSString stringWithFormat:#"%d", [item valueInDollars]]];
// Create a NSDateFormatter that will turn a date into a simple date string
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
// Use filtered NSDate object to set dateLabel contents
[dateLabel setText:[dateFormatter stringFromDate:[item dateCreated]]];
NSString *imageKey = [item imageKey];
if (imageKey) {
// Get image for image key from image store
UIImage *imageToDisplay = [[BNRImageStore sharedStore]imageForKey:imageKey];
// Use that image to put on the screen in imageview
[imageView setImage:imageToDisplay];
} else {
// Clear the imageview
[imageView setImage:nil];
}
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// Clear first responder
[[self view]endEditing:YES];
// "Save" changes to item
[item setItemName:[nameField text]];
[item setSerialNumber:[serialNumberField text]];
[item setValueInDollars:[[valueField text] intValue]];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)io
{
if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad) {
return YES;
} else {
return (io==UIInterfaceOrientationPortrait);
}
}
-(void)setItem:(BNRItem *)i
{
item = i;
[[self navigationItem] setTitle:[item itemName]];
}
- (IBAction)takePicture:(id)sender {
if ([imagePickerPopover isPopoverVisible]) {
// If the popover is already up, get rid of it
[imagePickerPopover dismissPopoverAnimated:YES];
imagePickerPopover = nil;
return;
}
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc]init];
// If our device has a camera, we want to take a picture, otherwise, we
// just pick from the photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
} else {
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
// This line of code will generate a warning right now, ignore it
[imagePicker setDelegate:self];
//Place image picker on the screen
// Check for iPad device before instantiating the popover controller
if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad) {
// Create a new popover controller that will display the imagepicker
imagePickerPopover = [[UIPopoverController alloc]initWithContentViewController:imagePicker];
[imagePickerPopover setDelegate:self];
// Display the popover controller; sender
// is the camera bar button item
[imagePickerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
}
-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
NSLog(#"User dismissed popover");
imagePickerPopover = nil;
}
- (IBAction)backgroundTapped:(id)sender {
[[self view]endEditing:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *oldKey = [item imageKey];
// Did the item already have an image?
if (oldKey) {
// Delete the old image
[[BNRImageStore sharedStore]deleteImageForKey:oldKey];
}
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Create a CFUUID object - it knows how to create unique identifier strings
CFUUIDRef newUniqueID = CFUUIDCreate(kCFAllocatorDefault);
// Create a string from unique identifier
CFStringRef newUniqueIDString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueID); // Incompatible integer to pointer conversion initializing
// Use that unique ID to set our item's imageKey
NSString *key = (__bridge NSString *)newUniqueIDString;
[item setImageKey:key];
// Store image in the BNRImageStore with this key
[[BNRImageStore sharedStore] setImage:image forKey:[item imageKey]];
CFRelease(newUniqueIDString);
CFRelease(newUniqueID);
[imageView setImage:image];
if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad) {
// If on the phone, the image picker is presented modally. Dismiss it.
[self dismissViewControllerAnimated:YES completion:nil];
} else {
// If on the pad, the image picker is in the popover. Dismiss the popover.
[imagePickerPopover dismissPopoverAnimated:YES];
imagePickerPopover = nil;
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
-(void)save:(id)sender
{
[[self presentingViewController]dismissViewControllerAnimated:YES
completion:nil];
}
-(void)cancel:(id)sender
{
// If the user cancelled, then remove the BNRItem from the store
[[BNRItemStore sharedStore]removeItem:item]; // No known class method for selector 'sharedStore'
[[self presentingViewController]dismissViewControllerAnimated:YES completion:nil];
}
DetailViewController.h
#import <UIKit/UIKit.h>
#class BNRItem;
#interface DetailViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate,UITextFieldDelegate, UIPopoverControllerDelegate>
{
__weak IBOutlet UITextField *nameField;
__weak IBOutlet UITextField *serialNumberField;
__weak IBOutlet UITextField *valueField;
__weak IBOutlet UILabel *dateLabel;
__weak IBOutlet UIImageView *imageView;
UIPopoverController *imagePickerPopover;
}
#property(nonatomic,strong)BNRItem *item;
-(id)initForNewItem:(BOOL)isNew;
- (IBAction)takePicture:(id)sender;
- (IBAction)backgroundTapped:(id)sender;
#end
BNRItemStore.m
#import "BNRItemStore.h"
#import "BNRItem.h"
#implementation BNRItemStore
+ (BNRItemStore *)defaultStore
{
static BNRItemStore *defaultStore = nil;
if(!defaultStore)
defaultStore = [[super allocWithZone:nil] init];
return defaultStore;
}
+ (id)allocWithZone:(NSZone *)zone
{
return [self defaultStore];
}
- (id)init
{
self = [super init];
if(self) {
allItems = [[NSMutableArray alloc] init];
}
return self;
}
- (void)removeItem:(BNRItem *)p
{
[allItems removeObjectIdenticalTo:p];
}
- (NSArray *)allItems
{
return allItems;
}
- (void)moveItemAtIndex:(int)from
toIndex:(int)to
{
if (from == to) {
return;
}
// Get pointer to object being moved so we can re-insert it
BNRItem *p = [allItems objectAtIndex:from];
// Remove p from array
[allItems removeObjectAtIndex:from];
// Insert p in array at new location
[allItems insertObject:p atIndex:to];
}
- (BNRItem *)createItem
{
BNRItem *p = [BNRItem randomItem];
[allItems addObject:p];
return p;
}
#end
BNRItemStore.h
#import <Foundation/Foundation.h>
#class BNRItem;
#interface BNRItemStore : NSObject
{
NSMutableArray *allItems;
}
+ (BNRItemStore *)defaultStore;
- (void)removeItem:(BNRItem *)p;
- (NSArray *)allItems;
- (BNRItem *)createItem;
- (void)moveItemAtIndex:(int)from
toIndex:(int)to;
#end
You are calling +sharedStore on BNRItemStore where your error occurs. This is because it really does not exist according to the code you posted.
All of the others calling +sharedStore are using the one presumably made available by BNRImageStore which you didn't provide. I assume it exists in that class? :)
In short, change:
[[BNRItemStore sharedStore]removeItem:item];
to
[[BNRImageStore sharedStore]removeItem:item];

Add text from UITextField to NSMutableArray and display it in UITableView

I am just starting with Objective-C to write iPhone apps. I read a couple books and made some projects with the books, but I am just not an expert yet. I am trying to add some text from a UITextField to an NSMutableArray and then display it in a UITableView. I know this is really basic stuff for most of you, but I am just a beginner. So far I have two files:
TableViewController.h:
#import <UIKit/UIKit.h>
#class AddItemViewController;
#interface TableViewController : UITableViewController {
AddItemViewController *addItemViewController;
NSMutableArray *itemsArray;
}
-(IBAction)addNewItem:(id)sender;
#property (nonatomic, retain)NSMutableArray *itemsArray;
#end
TableViewController.m
#import "TableViewController.h"
#import "AddItemViewController.h"
#implementation TableViewController
#synthesize itemsArray;
-(id)init
{
[super initWithStyle:UITableViewStyleGrouped];
itemsArray = [[NSMutableArray alloc] init];
[self setTitle:#"Playing Around"];
UIBarButtonItem *bbi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addNewItem:)];
[[self navigationItem] setLeftBarButtonItem:bbi];
[bbi release];
return self;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[self tableView] reloadData];
}
#pragma mark Actions
-(IBAction)addNewItem:(id)sender
{
addItemViewController = [[AddItemViewController alloc] init];
[UIView beginAnimations:#"animations" context:nil];
[[self navigationController] pushViewController:addItemViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView setAnimationDuration:0.7];
[UIView commitAnimations];
}
#pragma mark TableView Things
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return [itemsArray count];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *CellIdentifier = #"ItemCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell autorelease];
}
cell.textLabel.text = [itemsArray objectAtIndex:indexPath.row];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
- (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 {
[itemsArray release];
[super dealloc];
}
#end
AddItemViewController.h
#import <UIKit/UIKit.h>
#class TableViewController;
#interface AddItemViewController : UIViewController {
TableViewController *tableViewController;
IBOutlet UITextField *textField;
NSString *value;
}
-(IBAction)cancel:(id)sender;
-(IBAction)create:(id)sender;
#property (nonatomic, copy) NSString *value;
#property (nonatomic, retain)NSMutableArray *itemsArray;
#end
AddItemViewController.m
#import "AddItemViewController.h"
#import "TableViewController.h"
#implementation AddItemViewController
#synthesize value, itemsArray;
-(id)init
{
[self setTitle:#"Add Item"];
UIBarButtonItem *item;
item = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(cancel:)];
[[self navigationItem] setLeftBarButtonItem:item];
[item release];
item = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(create:)];
[[self navigationItem] setRightBarButtonItem:item];
[item release];
return self;
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[textField becomeFirstResponder];
}
-(void)viewDidUnload:(BOOL)animated
{
[super viewDidUnload];
[textField release];
textField = nil;
}
#pragma mark Actions
-(IBAction)cancel:(id)sender
{
tableViewController = [[TableViewController alloc] init];
[UIView beginAnimations:#"animations" context:nil];
[[self navigationController] pushViewController:tableViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView setAnimationDuration:0.7];
[UIView commitAnimations];
}
-(IBAction)create:(id)sender
{
//This is where I get lost
NSString *string = [textField text];
NSLog(#"The string is: %#", string);
[itemsArray addObject:string];
[[tableViewController tableView] reloadData];
NSLog(#"The items are: %#", itemsArray);
tableViewController = [[TableViewController alloc] init];
[UIView beginAnimations:#"animations" context:nil];
[[self navigationController] pushViewController:tableViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView setAnimationDuration:0.7];
[UIView commitAnimations];
}
- (void)dealloc {
[textField release];
[value release];
[super dealloc];
}
#end
(Sorry I put the whole thing here, but for all I know I could be doing something wrong in any part of this.)
So if you want to skip most of the stuff I think I did right just go to the create: method.
Now what do I do? I got this far, but the text from the UITableView will not show up when I try to add it to the itemsArray. Any tips would be great! Thanks in advance.
Your UITableView needs a data source. Your table view controller should implement the UITableViewDataSource protocol. Here are the docs.

Set Background using camera roll images

I want to know, how can I change my image app background using camera roll images. Any ideas??? How to get the camera roll paths or something like that!!!
Thanks!!!!
the following code uses a button on a toolbar, when pressed it will bring up the camera roll and then u will be able to pick the image to set
Start by adding the MobileCoreServices framework
add the following code in the .h file
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#interface cameraViewController : UIViewController
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate, UIPopoverControllerDelegate>
#property (nonatomic) BOOL newMedia;
#property (nonatomic, strong) IBOutlet UIImageView *imageView;
#property (nonatomic, strong) UIPopoverController *popoverController;
#property (nonatomic, strong) IBOutlet UIToolbar *toolbar;
- (IBAction)useCameraRoll: (id)sender;
#end
Add the following code in the .m file:
#synthesize imageView, popoverController, toolbar, newMedia;
- (IBAction) useCameraRoll: (id)sender
{
if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];
} else {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
self.popoverController.delegate = self;
[self.popoverController
presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
newMedia = NO;
}
}
}
#pragma mark -
#pragma mark UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.popoverController dismissPopoverAnimated:true];
NSString *mediaType = [info
objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info
objectForKey:UIImagePickerControllerOriginalImage];
self.imageView.image = image;
if (newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
#selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Save failed"
message: #"Failed to save image"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissModalViewControllerAnimated:YES];
}
Add the following in viewDidUnload:
- (void)viewDidUnload {
self.imageView = nil;
self.popoverController = nil;
self.toolbar = nil;
}
Dont forget to connect the imageview to your image and the cameraroll button to your button.
Check the docs for Assets Library.
-(void) uourCallingMethod{
UIImage *img = [UIImage imageNamed: [NSString stringWithFormat:#"image.jpg", i]];
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
(void) image:(UIImage *)image didFinishSavingWithError:(NSError *) error contextInfo:(void *) contextInfo{
}

UIView Shows perfect on the Simulator, but not iPhone?

Okay,
I have a really weird problem. When switching over to a different XIB, it shows on simulator but not on my test device. I will provide some code and screenshots of my layout in interface builder! Thanks in advance.
SettingViewController (what get's called to be displayed)
DetailViewController (what calls SettingsViewController to be displayed)
SettingsViewController.h
//
// SettingsViewController.h
//
// Created by Coulton Vento on 2/26/11.
// Copyright 2011 Your Way Websites. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "TableViewAppDelegate.h"
#import "Sqlite.h"
#class SettingsStoreViewController;
#interface SettingsViewController : UIViewController {
}
#end
SettingsViewController.m
#import "SettingsViewController.h"
#import "TableViewAppDelegate.h"
#implementation SettingsViewController
- (void)viewDidLoad {
NSString *myDB = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"flashpics.db"];
database = [[Sqlite alloc] init];
[database open:myDB];
TableViewAppDelegate *dataCeter = (TableViewAppDelegate *)[[UIApplication sharedApplication] delegate];
myTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector: #selector(updateNumber) userInfo: nil repeats: YES];
self.navigationItem.title = #"Album Settings";
NSString *post =[NSString stringWithFormat:#"id=%#", dataCeter.dataTwo];
NSString *hostStr = #"http://myflashpics.com/iphone_processes/get_album.php?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if ([serverOutput rangeOfString:#"yes"].location == NSNotFound) {
//NSLog(#"Fail - %# / %#", usernameField.text, passwordField.text);
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Please check your internet connection" delegate:self cancelButtonTitle:#"Try Again" otherButtonTitles:nil, nil];
[alertsuccess show];
[alertsuccess release];
[alertsuccess setTag:6];
} else {
NSArray *myWords = [serverOutput componentsSeparatedByString:#"?!?divide?!?"];
NSString *albumNameResults = [myWords objectAtIndex:1];
NSString *albumCommentsResults = [myWords objectAtIndex:2];
NSString *albumPrivateResults = [myWords objectAtIndex:3];
NSString *numberOfConnections = [myWords objectAtIndex:4];
albumName.text = albumNameResults;
numberButton.text = numberOfConnections;
if ([numberOfConnections isEqualToString:#"1"]) {
connectionsButton.text = #"Connection";
} else {
connectionsButton.text = #"Connections";
}
if ([albumCommentsResults isEqualToString:#"yes"]) {
[albumComments setOn:YES animated:YES];
} else {
[albumComments setOn:NO animated:YES];
}
if ([albumPrivateResults isEqualToString:#"yes"]) {
[albumPrivate setOn:YES animated:YES];
} else {
[albumPrivate setOn:NO animated:YES];
}
}
}
DetailViewController.h
#import <UIKit/UIKit.h>
#import "Sqlite.h"
#import "OHGridView.h"
#import "BigView.h"
#import "SettingsViewController.h"
#import "processViewController.h"
#class SecondView;
#class BigView;
#class CaptionView;
#interface DetailViewController : UIViewController <OHGridViewDelegate, OHGridViewDataSource> {
}
#end
DetailViewController.m
//
// DetailViewController.m
// TableView
//
// Created by iPhone SDK Articles on 1/17/09.
// Copyright www.iPhoneSDKArticles.com 2009.
//
#import "DetailViewController.h"
#import "TableViewAppDelegate.h"
#import "processViewController.h"
#implementation DetailViewController
#synthesize selectedCountry;
#synthesize selectedID;
- (IBAction)switchViews {
[self presentModalViewController:bigView animated:YES];
}
- (void)viewWillAppear {
[(OHGridView *)self.view reloadData];
NSLog(#" --- %# --- ", items);
}
- (IBAction)showSettings {
TableViewAppDelegate *dataCeter = (TableViewAppDelegate *)[[UIApplication sharedApplication] delegate];
dataCeter.dataTwo = selectedID;
SettingsViewController *screentwothree = [[SettingsViewController alloc] initWithNibName:nil bundle:nil];
screentwothree.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:screentwothree animated:YES];
[screentwothree release];
//[self.navigationController pushViewController:screentwothree animated:YES];
//[screentwothree release];
//screentwothree = nil;
}
/*
// 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
}
- (void)dealloc {
[selectedCountry release];
[lblText release];
[super dealloc];
}
#end
Sorry for all the code.
This sort of thing is often due to a difference in file systems: MacOS is typically case-insensitive, while iOS is always case-sensitive. So if you specify the .xib as "myview.xib" but it's actual name is "MyView.xib", that'll generally work on the simulator but not on the device. Same thing happens with images and other resources.