i want to get the label value by using perform button action using uicollectionviewcell in iOS. i have four label add as subview to uibutton in uicollectionviewcell. how to get the selected index uilabel value using button action.
You have to create a custom collection view cell class subclassed from UICollectionViewCell.In that class you can create labels and buttons from the storyboard.
#import <UIKit/UIKit.h>
#interface AudioListViewCell : UICollectionViewCell
#property (retain, nonatomic) IBOutlet UILabel *lbl1;
#property (retain, nonatomic) IBOutlet UILabel *lbl2;
#property (retain, nonatomic) IBOutlet UILabel *lbl3;
#property (retain, nonatomic) IBOutlet UIButton *button;
#end
Change the Class name of collectionview cell in story board as custom cell class name.Here AudioListViewCell.
In your viewcontroller in the collection view delegate method "didSelectItemAtIndexPath" you can get the labels text vlaue.This is one approach.
If you want to get the label text in button click, you have to add selector for the button in collectionvew cell and each buttons tag value is same as collection view index. Then You can get each label inside a button using the followng code.
for (UILabel * lbl in button.subviews) {
if(lbl1.tag == uniqueLabelTag1)strVal1= lbl1.text;
else if(lbl2.tag == uniqueLabelTag2)strVal2= lbl2.text;
else if (lbl3.tag == uniqueLabelTag3) strVal3 = lbl3.text;
}
You can create label tag from button tag ie. for example if your button tag of first collection view cell is 1 then your lbl1 tag can 1100, lbl2 tag can 1200 and lbl3 tag can 1300.If second button tag will be 2 then lbl1 tag can 2100, lbl2 can 2200 and lbl3 tag can 2300 and so on.
Related
I am having issues when I want to assign UIPicker as inputView of UITextField. It shows error " Assignement to readonly property". Please help as I think it is not related to property sythesizing.
I have added my code below:
#interface DriverWaitingDetails : UIViewController<UITextFieldDelegate,UIPickerViewDataSource, UIPickerViewDelegate>
{
IBOutlet UILabel *baseLabel;
IBOutlet UITableView *driverTableView;
IBOutlet UIPickerView *basePicker;
}
#property(nonatomic, retain) IBOutlet UIPickerView *basePicker;
#property(nonatomic,retain)IBOutlet UILabel *baseLabel;
#property(nonatomic,retain)IBOutlet UITableView *driverTableView;
#end
Implementation Code:-
-(void)viewDidLoad
{
basePicker=[[UIPickerView alloc] initWithFrame:CGRectMake(0,100,320, 500)];
self.navigationItem.title=#"Driver Table";
baseLabel.userInteractionEnabled = YES;
basePicker.delegate = self;
basePicker.dataSource = self;
[basePicker setShowsSelectionIndicator:YES];
baseLabel.inputView=nil;
[super viewDidLoad];
}
Attached Screenshot:-
You are setting the input view of UILabel.
You declared baseLabel as UILabel not UITextField.
IBOutlet UILabel *baseLabel;
You have declared
IBOutlet UILabel *baseLabel;
UILabel inherits from UIView : UIResponder : NSObject and the property is defined in UIResponder:
#property (readonly, retain) UIView *inputView
As the property inputView is read only, you cannot assign any value to it.
I want to make a drop down list for iphone application i want that when user click it show list and when click on any button it shows that value and hides list i have implemented using the follwoing code but this work only for one value not for others
#interface DropDownViewController : UIViewController {
IBOutlet UILabel*ddText;
IBOutlet UILabel*ddMenu;
IBOutlet UIButton*ddMenuShowButton;
}
#property (nonatomic, retain) IBOutlet UILabel *ddText;
#property (nonatomic, retain) IBOutlet UIView *ddMenu;
#property (nonatomic,retain) IBOutlet UIButton *ddMenuShowButton;
- (IBAction)ddMenuShow:(UIButton *)sender;
- (IBAction)ddMenuSelectionMade:(UIButton *)sender;
#end
#implementation DropDownViewController
#synthesize ddMenu, ddText;
#synthesize ddMenuShowButton;
- (IBAction)ddMenuShow:(UIButton *)sender
{
self.ddMenu.hidden = NO;
[sender setTitle:#"▲" forState:UIControlStateNormal];
}
- (IBAction)ddMenuSelectionMade:(UIButton *)sender
{
self.ddText.text = sender.titleLabel.text;
[self.ddMenuShowButton setTitle:#"▼" forState:UIControlStateNormal];
self.ddMenu.hidden = YES;
}
I have three button red grenn blue first is red it works only for red only not for others how to solve this i have used this following this tutorial
http://www.edumobile.org/iphone/iphone-programming-tutorials/a-simple-drop-down-list-for-iphone/
Add UIbutton near your textfield.While clicking that button create UITableview according to your textfileld size.(Hope you know about creating Uitableview)and then load your listview contents in "cellForRowIndex".While selecting the row of the table,you can get the value from "didselectrowatIndexPath" and load it in textfield.After that remove UItableview.
It would be good if you use iPhone tools in your application. You should use UIPickerView in the place of drop down list. It looks good and provides better interface in mobile application
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!!
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
I have this in my .h controller
#interface helloViewController : UIViewController {
IBOutlet UIlabel *label;
}
-(IBAction)hello:sender(id);
#end
I opened the corresponding .xib file and I could drag and associate the button -hello to the file owner but trying to associate the label doesn't work: it suggests me to associate -view outlet instead why ?
Your method declaration should be:
-(IBAction)hello:(id)sender;
Also, UILabel needs a capital L
IBOutlet UILabel *label