tableview image to be display in detailview - iphone

DetailsViewController.h
{
UIImageView *Image;
}
#property(retain, nonatomic) IBOutlet UIImageView* Image;
DetailsViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.Title.text = location.title;
self.desc.text = location.description;
this is the code to pull data from plist whenever user select a row in the uitableview..so the problem i am having now is how should i do it if i wan it to display an image?can't seems to get it after a few attempts..greatly appreciate!

if you are looking for just the way to display an image, it is simple.
on Interface Builder,
make Image View
make connection between 1 and Outlet
set the image path (short cut : Command + 1)

If you want to load this image into a UIImageView as suggested by cappucino, setup an IBOutlet like this so you have something to connect it to.
// in your header (.h) file in the interface definition
IBOutlet UIImageView *myIBImage;
// and at the bottom with your property declarations
#property (nonatomic, retain) UIImageView *myIBImage;
Also synthesize it at the top of you implementation file (.m)
#synthesize myIBImage;
Then in Interface Builder make the connections like this http://vimeo.com/3780487
Once connected, you can load the image into memory and set it to the view for your UIImageView.
// load an image from the bundle's path into memory
NSString* tmpStr = #"/myImage.png";
[myIBImageView setImage:[UIImage imageNamed:tmpStr]];
That's it. Who said iPhone coding is hard?
(Yes it is tricky, but you'll do it so often you'll hardly notice!) :D

Related

iOS 6 issue during setting text on a label

I've a problem with some label. I made a public method that takes information from a table view and shows this info in 3 label, a text view and it load a pic from the web. I setup all the variable in the table view didSelectRowAtIndexPath method, but I'm having some issue to display that info. I made so:
in the table view controller I called the other method so:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.detailCharacterViewController = [[DetailCharacterViewController alloc] init];
[self.detailCharacterViewController setupDetailViewControllerWithName:[self.arrayCharacters[indexPath.row] objectForKey:#"name"] andSurname:[self.arrayCharacters[indexPath.row] objectForKey:#"surname"] andKind:[self.arrayCharacters[indexPath.row] objectForKey:#"kind"] andDescription:[self.arrayCharacters[indexPath.row] objectForKey:#"description"] andImage:[self.arrayCharacters[indexPath.row] objectForKey:#"URLpic"]];
}
and I implemented the method so:
- (void)setupDetailViewControllerWithName:(NSString*)name andSurname:(NSString *)surname andKind:(NSString*) kind andDescription:(NSString*)description andImage:(NSString*)url {
NSLog(#"name = %#", name);
self.labelName.text = name;
self.labelSurname.text = surname;
self.labelKind.text = kind;
self.textDescription.text = description;
NSURL *urlPic = [NSURL URLWithString:url];
NSData *dataPic = [NSData dataWithContentsOfURL:urlPic];
[self.imagePic setImage:[UIImage imageWithData:dataPic]];
}
If I look to the log i see the right things, but if I look to the GUI on iPhone or iPhone simulator it will remain blank. What's wrong with this code?
Thank you for the suggestion.
#Alex Blundell
#import <UIKit/UIKit.h>
#interface DetailCharacterViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *labelName;
#property (weak, nonatomic) IBOutlet UILabel *labelSurname;
#property (weak, nonatomic) IBOutlet UILabel *labelKind;
#property (weak, nonatomic) IBOutlet UIImageView *imagePic;
#property (weak, nonatomic) IBOutlet UITextView *textDescription;
- (void)setupDetailViewControllerWithName:(NSString*)name andSurname:(NSString *)surname andKind:(NSString*) kind andDescription:(NSString*)description andImage:(NSString*)url;
#end
The problem is that your DetailCharacterViewController's view is not loaded yet when you call setupDetailViewControllerWithName:..., so none of the outlets are connected (yet). Instantiating a view controller via alloc-init does not load its view automatically.
You could force loading the view by calling [self view] at the beginning of your setup method. This works because accessing the view property will automatically load the view if it wasn't loaded before.
Alternatively, you could make the name, surname, etc. NSString properties of the view controller and set the corresponding labels in viewDidLoad.
Are you using Interface Builder/Storyboards to design your interface? Have you made sure to connect the IBOutlets for each UITextField/View?
You should identify the objects in the header file on your view controller class, and ensure they're prefixed by IBOutlet for them to appear in Interface Builders connections pane. E.g.
IBOutlet UITextField labelName;
[...]
Then you need to go to IB and go to the connections pane for the view controller to connect each text field/view.
This problem happened to me as well.
It has to do with the fact that iOS actually hooks up your outlets really really late.
If you put a breakpoint in your setupDetailViewControllerWithName: and check your IBOutlet variables, they will be nil. That's why you are seeing a blank view. (The good old nil erroring)
The work-around I will do is to declare properties in the DetailCharacterViewController class. (Such as #property (copy, nonatomic) NSString* name).
And in the place where you are calling setupDetailViewControllerWithName:, set those properties instead such as:
self.detailCharacterViewController.name = name;
Finally in your DetailCharacterViewController's viewDidLoad:, you set the values of the labels using the saved properties. (The outlets are for sure hooked up then).
(By the way, this problem exists for prepareForSegue: as well. The destination view controller's outlets are all still nil in prepareForSegue:. So you cannot set them directly there yet)

UIScrollView stops working when label text in UIScrollView is changed

I have had this problem for a long time now, I hope stackoverflow can help!
THE PROBLEM IS
When I enter "Alan Shearer" into the EnterNameText (UI TEXTFIELD) the label changes text, however the ScrollView no longer scrolls to the set content size, it will scroll a little bit, but no were near the set content size, in this case 2000px in height.
details
1) Xcode 4.5.1
2) IOS 6
In my .xib file ( tinypic.com/view.php?pic=2h4yx3o&s=6 ) I have a UIScrollView (320 pixels in width, and 490 pixels in height)
The UIScrollView contains labels that are all connected to view controller.h.
The Label (all labels are set in the same way) :
#property (strong, nonatomic) IBOutlet UILabel *AlanShearerLabel;
my UIScrollView in ViewController.h looks like this:
#property (strong, nonatomic) IBOutlet UIScrollView *scrollview;
UIScrollView in ViewController.m
- (void)viewDidAppear:(BOOL)animated{[super viewDidAppear:animated]; self.scrollview.contentSize=CGSizeMake(320.0, 2000.0); }
An IBAction called - (IBAction)CheckButton:(id)sender
The action when CheckButton is clicked:
//string 0
NSString *string0 = _EnterNameText.text;
//Alan Shearer
NSString *string1 =#"Alan Shearer";
NSString *string2 =#"Rank 1) Alan Shearer 260 Goals";
NSString *stringshearer =#"Shearer";
//Alan Shearer IF
if([string0 isEqualToString:string1]||
[string0 isEqualToString:stringshearer])
{_AlanShearerLabel.text = string2;
_AlanShearerLabel.textColor = [UIColor greenColor];
_EnterNameText.text=#"";
}
To solve this issue you must be sure to define all the things inside the scrollview before you link the scrollview to the .h file. For example if you have 20 labels in a scrollview, be sure that the 20 labels have been connected to the .h file, set the right size, put in the right place. Only then do you connect your scrollview to the .h file and place the scrollview code in viewDidAppear rather then viewdidload.

Can't pass UITableViewCell didSelectRowAtIndexPath data to another view controller

I have currently got a UITableView in my main view controller. I want the data of the selected row to be passed to another view controller in my project.
Here's what I have got so far, although there is an error. Why is this? I have referenced the class and the header file in my .h file.
I would really appreciate some help with this as I've tried everything I can think of.
Simply synthesize the object in the destination view.
It will work fine...
like:
in .h
#property(nonatomic, retain) UILabel *note;
in .m
#synthesize note;
Very Simple,I think note is a UILabel,
according to You error
please use this code in AddNote. h file
NSString *noteStr; //Ios 4
IBoutlet UILabel *note;
#property(nonatomic, retain) NSString *noteStr; //Ios 4
#property(nonatomic, retain) UILabel *note;
#property(nonatomic, strong) NSString *noteStr;
#property(nonatomic, strong) UILabel *note; //Ios 5
In AddNote. .m file
#synthesize note,noteStr;
self.note.text=noteStr; //in ViewWillAppear
Some Time Application is crash Because Memory IF you Work In Ios 4 Please Correct this code
an.noteStr - [selectNote retain];
Declare static variable for global use.
Using keyword extern
Create Common.h
extern NSMutableArray *gMyBasketCollectionList;
common.m
NSMutableArray *gMyBasketCollectionList;
Use This Mutable Aarray to Store Your Data and Display in Any other
include common.h in First View And SecondView
Add Object to mutable Array in First View And
Show SecondView And Display access that Array

Multiple images in UITableViewCell with action attached in iPhone

I want to show multiple image in each cell of TableView which is coming from server and I dont know the exact number of images in each table cell.Also when user clicks on any of the images then it will zoom in another view controller.
My question is how to design such table with dynamic height and how to know which images is tapped for zooming.Thanks
i have designed same table as you are currently working on.
For that i have taken UIScrollview in each tableview cell so images that are coming from server will display in scrollview.
And to display images inside the scrollview, i have taken UIButton so i can identify which image is pressed.
This is basic idea what i am doing.
Enjoy!
Try a making a custom Tableview cell with buttons. you can put your images in the button and onclick you can get the sender tag and display the respective image in another view controller
There are many tutorials available on the internet on making a grid view in ios check them out.
Here is a link of one to get you started
Hope this helps.
http://xebee.xebia.in/2011/04/14/building-editable-gridview-for-iphone-apps/
Here we go: you need a custom cell to hold the photos array.
You need a custom UIImageView to track the touch. For this you have 2 options: you add a button on top, or you use -touchesBegan (see below).
Now, when you tap a picture, it will tell it's parent (the cell) which photo was pressed.
The cell will forward the information to the RootViewController (the class with the UITableView) also adding itself to the information.
Classes needed:
RootViewController (not implemented here)
Cell
CustomImageView
//Cell.h
import UIKit/UIKit.h
#class RootViewController;
#class CustomImageView;
#interface Cell : UITableViewCell
{
RootViewController *parent;
IBOutlet UIView *baseView; //I use this instead of content view; is more ..mutable
NSMutableArray *photosArray;
double cellHeight;
}
#property (nonatomic, assign) RootViewController *parent;
#property (nonatomic, retain) UIView *baseView;
#property (nonatomic, retain) NSMutableArray *photosArray;
#property double cellHeight;
(void) didClickPhoto: (CustomImageView*) image;
#end
//Cell.m
import "Cell.h"
#implementation Cell
#synthesize baseView, photosArray, cellHeight, parent;
- (void) didClickPhoto: (CustomImageView*) image
{
unsigned indexOfSelectedPhoto = [photosArray indexOfObject:image];
//this will allow you to reffere the pressed image;
[parent didClickPhotoAtIndex: indexOfSelectedPhoto inCell: self];
//you will inplement this function in RootViewController
}
#end
CustomImageView.h
#import <UIKit/UIKit.h>
#import "Cell.h"
#interface CustomImageView : UIImageView {
Cell *parent;
}
#property (nonatomic, assign) Cell *parent;
#end
CustomImageView.m
#import "CustomImageView.h"
#implementation CustomImageView
#synthesize parent;
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
[parent didClickPhoto:self];
}
#end
And that would be the longest answer I ever wrote!!

Objective C / iPhone - how to bind UISlider to code

I'm just starting with Objective C, but I'm already running into a problem:
When I did this in the past, I had no problem with it:
I made a new UISlider, clicked it, CTRL dragged a blue line to the code, and somehow I was then able to read it's values.
However, I am now running into the problem that I can't draw those lines anymore.
By messing around I managed to get buttons to work, but the slider just won't work.
my Mainwindow.xib has got the iSaturateViewController class,
iSaturateViewController.xib has got the whole interface in it.
How can I get the UISlider to work without being able to draw that line?
How I have it now:
(in iSaturateViewController.h)
#import <UIKit/UIKit.h>
#interface iSaturateViewController : UIViewController {
UISlider * satSlider;
UILabel * satLabel;
}
#property (nonatomic, retain) IBOutlet UISlider * satSlider;
#property (nonatomic, retain) UILabel * satLabel;
-(IBAction) changeSaturation:(id) sender;
#end
(in iSaturateViewController.m):
#synthesize satLabel,satSlider;
-(IBAction) changeSaturation:(id)sender {
satLabel.text = [[NSString alloc] initWithFormat:#"Saturation: %d ", (Float32)satSlider.value];
NSLog(#"%f", satSlider.value);
}
Ath the moment the NSLog shows: 0.00000000
Also, I've set the Label in the Identity properties to: satSlider (slider) and satLabel (label).
Just to clarify my goal:
I want the slider's (satSlider) value to show in the UILabel (satLabel) via the function changeSaturation.
How can I do this?
Add the method declaration:
-(IBAction) changeSaturation:(id)sender;
to the header file iSaturateViewController.h
Then, assign the Value Changed action of your UISlider to your changeSaturation method. Right click on the slider and drag the Value Changed to the File's Owner and connect them. It should work.
You can also try this:
-(IBAction)changeSaturation:(id)sender {
UISlider *slider = (UISlider *)sender;
satLabel.text = [NSString stringWithFormat:#"Saturation: %f", slider.value];
NSLog(#"Saturation: %f", slider.value);
}
Regarding UILabel - add IBOutlet and connect it in the Interface Builder. The interface should be like that:
#import <UIKit/UIKit.h>
#interface iSaturateViewController : UIViewController {
IBOutlet UISlider * satSlider;
IBOutlet UILabel * satLabel;
}
#property (nonatomic, retain) IBOutlet UISlider * satSlider;
#property (nonatomic, retain) IBOutlet UILabel * satLabel;
-(IBAction) changeSaturation:(id) sender;
#end
Let me know if it works.
Looks like the key thing you’re missing is that the satSlider outlet isn’t hooked up, so its value is nil. You connected the slider’s action to the -changeSaturation: method, but it sounds like you didn’t also connect the satSlider property to the slider itself. Sending a message (like value in this case) to nil doesn’t do anything, and returns 0, so 0 is the value you’re getting out of it. Hook up your outlet by Ctrl-dragging from the property in the code to the slider in your UI and it should work.
You need to edit your header and add the method declaration. Then in IB, associate the first responder for value changed to the UISlider. Also slider.value, you need to read article: Setting interval value for UISlider