Multiple images in UITableViewCell with action attached in iPhone - 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!!

Related

how to make a drop down list for iphone application

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

How to add a popup UIView (of a customized class) on a UIViewController

I'm new on this, and I would like to get some advice because I don't know what I'm doing wrong.
I want to make an app in xcode, with a UIView with some items, and when you do something, another UIView (smaller than the first) pops up above the first UIView. The popup UIView would be a customized class.
I have started with the UIViewController template and the initial UIView, and I have linked all the items in the .storyboard, and it works. But when I create my own UIView class (from objective-C class), put the second UIView over the first in the storyboard and link it to my class, something goes wrong.
The UIView appears, but when I try to set it to hidden, it doesn't answer. It's like it's not receiving the messages, so I think I don't link it well programmatically and just appears because of the storyboard.
I don't know if I have to create another UIViewController instead of the UIView, or if this is the correct path.
Can anybody explain me a little, or just write a little code snippet with the instantiation of the second view and adding it?
Lots of thanks!!
(I paste some code, of the declaration in .h and instantiation in .m)
#import <UIKit/UIKit.h>
#import "EditView.h"
#interface ReleaseViewController : UIViewController <UIWebViewDelegate, UISearchBarDelegate> {
IBOutlet UIWebView *web;
IBOutlet UISearchBar *search;
IBOutlet EditView *evHack;
}
#property (nonatomic, retain) IBOutlet UIWebView *web;
#property (nonatomic, retain) IBOutlet UISearchBar *search;
#property (nonatomic, retain) IBOutlet EditView *evHack;
#end
- (void)viewDidLoad
{
[super viewDidLoad];
search.delegate = self;
web.delegate = self;
evHack = [evHack initWithFrame:CGRectMake(0, 44, 320, 377)];
[evHack setHidden:YES];
}
EditView Class (I still have nothing):
#import <UIKit/UIKit.h>
#interface EditView : UIView
#end
#import "EditView.h"
#implementation EditView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(#"View created");
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#end
initWithFrame only works when you alloc/init an app. If its already initialized, in this case by the storyboard, just set its frame:
evHack.frame = CGRectMake(0,44, 320, 377);
I don't know what it looks like in IB, But setting its frame in code may be redundant if you set it in IB too. To check whether evHack is hooked up right, NSLog evHack in viewDidLoad. If you get nil back, it's not hooked up right.

resize the Hosting View through addSubview in Core-Plot in XCode 4

I'm running into a wall trying to resize the Hosting View. The problem is I either get a full-screen plot or a blank screen. I'm hoping to get some leads to fix this problem:
I'm using Xcode 4 | IOS 4.3 | Recently downloaded core plot using hg:
I have two xib files (MainWindow & my ViewController)
My ViewController.xib file contains two objects: a View and Hosting View both at the same level:
+-View
+-Graph Hosting View
I get no erros in my code, but all I get a blank screen. I've searched for 3 days how to get around this problem, but haven't found something that works.
My xAppDelegate.h
#import <UIKit/UIKit.h>
#class CorePlotTestViewController;
#interface CorePlotTestAppDelegate : NSObject <UIApplicationDelegate> {
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet CorePlotTestViewController *viewController;
#end
My ViewController.h
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
#interface CorePlotTestViewController : UIViewController <CPTPlotDataSource>
{
CPTXYGraph *graph;
NSMutableArray *dataForPlot;
CPTGraphHostingView *graphView;
}
#property(readwrite, retain, nonatomic) NSMutableArray *dataForPlot;
#property(nonatomic, retain)IBOutlet CPTGraphHostingView* graphView;
My ViewController.m
#import "CorePlotTestViewController.h"
#interface CorePlotTestViewController(private)
- (void) configureTableHeader;
#end
#implementation CorePlotTestViewController
#synthesize dataForPlot;
#synthesize graphView;
-(void)dealloc
{
[dataForPlot release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self configureTableHeader];
}
- (void) configureTableHeader
{
// here I implement the contents of the Hosting View
graph = [[CPTXYGraph alloc] initWithFrame: CGRectZero];
CPTGraphHostingView *hostingView = [(CPTGraphHostingView *)[CPTGraphHostingView alloc]
initWithFrame:CGRectZero];
[self.view addSubview:hostingView];
...
// etc
...
}
In your code, you initialize the hosting view using a CGRectZero frame, which is basically a frame with an origin at (0,0) and both a width and a height of 0 px. It is the reason why you don't see the graph at all when you run your project.
If you gave a custom size and location to the hosting view in Interface Builder, it is overridden by this code.
By the way, I'm not sure why you want to add the hosting view to the controller's view in the code. You just need to layout both components using Interface Builder, giving the hosting view the size and the location you want it to have.
Last thing : why do you add a 'T' to Core-Plot class names ? CPTPlotDataSource should simply be CPPlotDataSource; CPTXYGraph: CPXYGraph; etc.

How to correctly detect touches in my UIView?

I'm having a problem. I have a UIView, that looks like this :
In that view controller I implemented the "touchesBegan:withEvent:" method, but the method is only getting triggered when I touch the bar at the bottom of the view , nothing happens when I touch the table.
How could I change this behavior to be able to detect the touches that occur in the table too ?
This is the code that basically declares that UIViewController:
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#interface TripSearchDetailViewController : UIViewController
{
//Parent of this sub-view.
UIViewController *parentController;
//GUI elements
UITableView *tableView;
UIButton *backButton;
}
//Button actions
- (IBAction) goBack:(id) sender;
- (IBAction) showDatePicker:(id) sender;
//Class Methods.
- (void) presentDatePicker;
#property (nonatomic, retain) UIViewController *parentController;
#property (nonatomic, retain) IBOutlet UITableView *tableView;
#property (nonatomic, retain) IBOutlet UIButton *backButton;
#end
It looks like you've got a UITableViewController, not a UIViewController. Your table view is intercepting and handling touches before they make it up to your view controller. You'll need to subclass UITableView, override it's -touchesBegan:withEvent: method, and then create a standard UIViewController that adds your new subclass to the view hierarchy.
I think it could possibly help to implement the method hitTest:withEvent: in your TripSearchDetailViewController. If you just return true in this method your touch should be recognized.
see also: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html

Passing object from controller to a view

I'm following iPhone dev courses from Stanford Open-University, and I've been blocked for 2 days on assignment3, maybe someone can help me here?
The tasks are:
Create a custom UIView subclass that will display your PolygonShape object
Give your view class access to the PolygonShape object so that it can retrieve the details of the polygon as needed
The problem is: how do I give my view class access to the polygon object defined in my controller?
Here is my implementations if it can help:
CustomView.h:
#import "PolygonShape.h"
#interface CustomView : UIView {
IBOutlet PolygonShape *polygon;
}
- (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides;
#end
Controller.h:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
#import "PolygonView.h"
#interface Controller : NSObject {
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
IBOutlet PolygonShape *polygon;
IBOutlet PolygonView *polygonView;
}
- (IBAction)decrease;
- (IBAction)increase;
- (void)awakeFromNib;
- (void)updateInterface;
#end
And after you figure it out, it might not hurt to touch up on some objective-c basics:
http://www.cocoacast.com/?q=node/103
Found my own answer, I missed a setPolygon method in my CustomView to link both... stupid...
in CustomView.h:
#import "PolygonShape.h"
#interface CustomView : UIView {
IBOutlet PolygonShape *polygon;
}
#property (readwrite, assign) PolygonShape *polygon;
- (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides;
#end
in CustomView.m:
#implementation CustomView
#synthesize polygon;
...
#end
in Controller.m:
- (void)awakeFromNib {
// configure your polygon here
polygon = [[PolygonShape alloc] initWithNumberOfSides:numberOfSidesLabel.text.integerValue minimumNumberOfSides:3 maximumNumberOfSides:12];
[polygonView setPolygon:polygon];
NSLog (#"My polygon: %#", [polygon description]);
}
I just finished assignement 3 last night. I solved this connection all in Interface Builder. First I created an outlet on the "PolygonView" UIView subclass for the PolygonShape and then connected it to the instance of the Polygon model. From what I have read in the Google Group and on various other sites, I do not think there is one right way to connect this UIView to the model and the controller. But it worked I think there is nothing wrong with the View knowing about the model.
So why aren't you declaring them as properties of the class?