i have an iPhone app with TabBarController that each tab has a Nav Controller.. one of the Nav Controller pushes to another Viewcontroller. in that View Controller i am trying to Hide the back button and place One of my custom buttons. in the
- (void)viewDidLoad
{
[super viewDidLoad];
self._allUsersParticipantsInTheVideo = [[NSMutableArray alloc] init];
self._allUsersInvitesInTheVideo = [[NSMutableArray alloc] init];
for (int i=0; i < [self._curVideoToShow._videoParticipants count]; i++) {
[self._allUsersParticipantsInTheVideo addObject:[self._curVideoToShow._videoParticipants objectAtIndex:i]];
}
for (int i=0; i < [self._curVideoToShow._videoInvitees count]; i++) {
[self._allUsersInvitesInTheVideo addObject:[self._curVideoToShow._videoInvitees objectAtIndex:i]];
}
[self setNavBar];
}
#pragma mark - Set NavBar
-(void)setNavBar{
self.navigationItem.hidesBackButton = YES;
UIView *navBarItemview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[navBarItemview setBackgroundColor:[UIColor clearColor]];
// Set cutsom back button
//UIImage *backImage = [UIImage imageNamed:#"backButton.png"];
UIImage *backImage = [UIImage imageNamed:#"LeftArrowBg.png"];
CGRect frame = CGRectMake(0, 6, backImage.size.width + 4, backImage.size.height);
UIButton *bttn = [[UIButton alloc] initWithFrame:frame];
[bttn setBackgroundImage:backImage forState:0];
[bttn setTag:kBackBttn];
[bttn setTitle:#"Back" forState:UIControlStateNormal];
[bttn setTitleEdgeInsets:UIEdgeInsetsMake(4, 5, 0, 0)];
[bttn.titleLabel setFont:[UIFont fontWithName:#"PTSans-Bold" size:12.0]];
[bttn setContentMode:UIViewContentModeScaleAspectFit];
[bttn addTarget:self action:#selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[navBarItemview addSubview:bttn];
UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 4, 320, 40)];
[titleLbl setFont:[UIFont fontWithName:#"PTSans-Bold" size:24.0]];
[titleLbl setTextColor:[UIColor whiteColor]];
[titleLbl setTextAlignment:UITextAlignmentCenter];
[titleLbl setBackgroundColor:[UIColor clearColor]];
[titleLbl setTag:kTitleLbl];
[titleLbl setShadowOffset:CGSizeMake(0, 1)];
[titleLbl setShadowColor:[UIColor blackColor]];
[titleLbl setText:#"All Participants"];
[navBarItemview addSubview:titleLbl];
self.navigationItem.titleView = navBarItemview;
}
As you can see i've written :
self.navigationItem.hidesBackButton = YES;
but on the first time when the app is lunched, i see the back button of the NavBar only for the first time, but later on for every time that i open the app the button remains to be my custom one. ( and also when i Navigate it is my custom )
someone?
try with this..
-(void)viewWillAppear:(BOOL)animated
{
self.navigationItem.hidesBackButton = YES;
}
or
[self.navigationController.navigationItem setHidesBackButton:YES];
or
self.navigationController.navigationItem.backBarButtonItem = nil;
I am new to this iphone development .I am now stuck with a problem .In my application i require coverflow in which multiple labels should be shown.So for that i added an image as a sub view for view and then added the labels as a sub view for the image view.Every thing works fine for the first 7 elements But when i scroll it is showing the same elements again
I am using
https://github.com/nicklockwood/iCarousel
this to attain coverflow
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(ReflectionView *)view
{
UIImageView *imageView =nil;
UILabel *yourLabel=nil;
UILabel *yourLabel1=nil;
UILabel *yourLabel2=nil;
cardAvailableDataObject *singleCard=[self.cards objectAtIndex:index];
if (view == nil)
{
//set up reflection view
view = [[[ReflectionView alloc] initWithFrame:CGRectMake(0,0,200,self.view.frame.size.width/1.42)] autorelease];
imageView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(0,0,200,self.view.frame.size.width/1.42)];
[view addSubview:imageView];
yourLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, -5, 200, 50)];
yourLabel.textAlignment = UITextAlignmentCenter;
[yourLabel setTextColor:[UIColor colorWithRed:(38/255.f) green:(171/255.f) blue:(226/255.f) alpha:1.0f]];
[yourLabel setBackgroundColor:[UIColor clearColor]];
[yourLabel setFont:[UIFont fontWithName: #"Trebuchet MS" size: 17.0f]];
[imageView addSubview:yourLabel];
yourLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(90, 40, 300, 20)];
[yourLabel1 setTextColor:[UIColor blackColor]];
[yourLabel1 setBackgroundColor:[UIColor clearColor]];
[yourLabel1 setFont:[UIFont fontWithName: #"Trebuchet MS" size: 12.0f]];
[imageView addSubview:yourLabel1];
yourLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(90, 61, 300, 20)];
[yourLabel2 setTextColor:[UIColor blackColor]];
[yourLabel2 setBackgroundColor:[UIColor clearColor]];
[yourLabel2 setFont:[UIFont fontWithName: #"Trebuchet MS" size: 12.0f]];
[imageView addSubview:yourLabel2];
}
else
{
imageView = [[view subviews] lastObject];
yourLabel = [[imageView subviews] lastObject];
yourLabel1 = [[imageView subviews] lastObject];
yourLabel2= [[imageView subviews] lastObject];
}
yourLabel.text=singleCard.name;
yourLabel2.text=singleCard.companyname;
yourLabel1.text=singleCard.designation;
imageView.image=[profile objectAtIndex:index];
return view;
}
This is my code .Can any one suggest how to solve this
- (IBAction) showCatPicker {
if (self.catList !=nil) {
self.catList=nil;
[catList release];
}
self.catList = [[NSMutableArray alloc] init];
self.actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[self.actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
if(self.catPicker == nil) {
self.catPicker = [[UIPickerView alloc] initWithFrame:pickerFrame];
self.catPicker.showsSelectionIndicator = YES;
self.catPicker.dataSource = self;
self.catPicker.opaque = YES;
self.catPicker.multipleTouchEnabled = YES;
self.catPicker.userInteractionEnabled = YES;
self.catPicker.delegate = self;
}
[self.actionSheet addSubview:self.catPicker];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Select"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor colorWithRed:19.0/255 green:122.0/255 blue:53.0/255 alpha:1.0];
[closeButton addTarget:self action:#selector(dismissGenderPicker:) forControlEvents:UIControlEventValueChanged];
UISegmentedControl *cancelButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Cancel"]];
cancelButton.momentary = YES;
cancelButton.frame = CGRectMake(10, 7.0f, 50.0f, 30.0f);
cancelButton.segmentedControlStyle = UISegmentedControlStyleBar;
cancelButton.tintColor = [UIColor colorWithRed:19.0/255 green:122.0/255 blue:53.0/255 alpha:1.0];
[cancelButton addTarget:self action:#selector(cancelActionSheet) forControlEvents:UIControlEventValueChanged];
[self.actionSheet addSubview:cancelButton];
[self.actionSheet addSubview:closeButton];
[cancelButton release];
[closeButton release];
[self.actionSheet showInView:self.view];
[self.actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
[catPicker reloadComponent:0];
}
You should definitely NOT use UIActionSheet to hold an UIDatePicker because this functionality is deprecated!
From the Documentation:
Subclassing Notes
UIActionSheet is not designed to be subclassed, nor should you add
views to its hierarchy. If you need to present a sheet with more
customization than provided by the UIActionSheet API, you can create
your own and present it modally with
presentViewController:animated:completion:.
and
Important: UIActionSheet is deprecated in iOS 8. (Note that
UIActionSheetDelegate is also deprecated.) To create and manage action
sheets in iOS 8 and later, instead use UIAlertController with a
preferredStyle of UIAlertControllerStyleActionSheet.
What you could very easily do is to create an UIView to hold the UIDatePicker and animate the view as appropriate. You can even add an UIToolbar to it if you need to.
Here's an example:
Create two properties:
#property (strong, nonatomic) UIDatePicker *theDatePicker;
#property (strong, nonatomic) UIView *pickerView;
Create your picker, embed it into the UIView and show:
-(void) createDatePickerAndShow {
UIToolbar *controlToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, pickerView.bounds.size.width, 44)];
[controlToolbar sizeToFit];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *setButton = [[UIBarButtonItem alloc] initWithTitle:#"Set" style:UIBarButtonItemStyleDone target:self action:#selector(dismissDateSet)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:#selector(cancelDateSet)];
[controlToolbar setItems:[NSArray arrayWithObjects:spacer, cancelButton, setButton, nil] animated:NO];
[theDatePicker setFrame:CGRectMake(0, controlToolbar.frame.size.height - 15, theDatePicker.frame.size.width, theDatePicker.frame.size.height)];
if (!pickerView) {
pickerView = [[UIView alloc] initWithFrame:theDatePicker.frame];
} else {
[pickerView setHidden:NO];
}
CGFloat pickerViewYpositionHidden = self.view.frame.size.height + pickerView.frame.size.height;
CGFloat pickerViewYposition = self.view.frame.size.height - pickerView.frame.size.height;
[pickerView setFrame:CGRectMake(pickerView.frame.origin.x,
pickerViewYpositionHidden,
pickerView.frame.size.width,
pickerView.frame.size.height)];
[pickerView setBackgroundColor:[UIColor whiteColor]];
[pickerView addSubview:controlToolbar];
[pickerView addSubview:theDatePicker];
[theDatePicker setHidden:NO];
[self.view addSubview:pickerView];
[UIView animateWithDuration:0.5f
animations:^{
[pickerView setFrame:CGRectMake(pickerView.frame.origin.x,
pickerViewYposition,
pickerView.frame.size.width,
pickerView.frame.size.height)];
}
completion:nil];
}
And to dismiss the DatePicker:
-(void) cancelDateSet {
CGFloat pickerViewYpositionHidden = self.view.frame.size.height + pickerView.frame.size.height;
[UIView animateWithDuration:0.5f
animations:^{
[pickerView setFrame:CGRectMake(pickerView.frame.origin.x,
pickerViewYpositionHidden,
pickerView.frame.size.width,
pickerView.frame.size.height)];
}
completion:nil];
}
self.view.userInteractionEnabled = NO;
self.blurView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.blurView setBackgroundColor:[UIColor lightGrayColor]];
[self.blurView setAlpha:0.3];
[[[UIApplication sharedApplication] delegate].window addSubview:self.blurView];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:pickerFrame];
pickerView.datePickerMode = UIDatePickerModeDate;
[pickerView setBackgroundColor:[UIColor whiteColor]];
[pickerView addTarget:self action:#selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
__block CGRect frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, 220);
self.viewForPicker = [[UIView alloc] initWithFrame:frame];
[self.viewForPicker setBackgroundColor:[UIColor whiteColor]];
[self.viewForPicker addSubview:pickerView];
[[[[UIApplication sharedApplication] delegate] window] addSubview:self.viewForPicker];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
[button setTitle:#"Done" forState:UIControlStateNormal];
[button addTarget:self action:#selector(doneButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(250, 15, 60, 30)];
[button.layer setCornerRadius:5.0];
[button.layer setBorderWidth:1.0];
[button.layer setBorderColor:[[IMAppStyle appColor] CGColor]];
[self.viewForPicker addSubview:button];
[self.viewForPicker.layer setCornerRadius:8.0];
float animationDuration = 0.25;
[UIView animateWithDuration:animationDuration animations:^{
frame.origin.y -= (180+40+35);
[self.viewForPicker setFrame:frame];
}];
I can not set frame size of view controller & table view. Here is image of my view hierachy
Content view is added as subview in scroll view. My content view contains labels , buttons & text view which are added programatically.
But according to my code listed below , I can not set the table view frame & view controller frame. My table view is frame is not set correctly & thats why I have to scroll up/down to see my table cell contents. So I have 2 scrolls i.e. 1 for scroll view & 1 for table view.
Here is my code
#define TABLE_CELL_HEIGHT 200.0f
#define ADD_VIEW_HEIGHT 30.0f
#define FONT_SIZE 24.0f
#define CELL_CONTENT_WIDTH 720.0f
#define CELL_CONTENT_MARGIN 50.0f
#define SectionHeight 50.0f
#define LEFT_MARGIN 25
#define RIGHT_MARGIN 25
#define TOP_MARGIN 35
#define BOTTOM_MARGIN 50
#define BOTTOM_FOOTER_MARGIN 32
#define DOC_WIDTH 768
#define DOC_HEIGHT 910
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSLog(#"In viewDidLoad of PostDetailsViewController");
self.navigationItem.title = [post Title];
[self createUserInterface];
[self createCommentUserInterface];
self.contentView.backgroundColor = SET_BACKGROUND_IMAGE;
self.view.backgroundColor = SET_BACKGROUND_IMAGE;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self displayCommentsForPhotoID:[post ID]];
[self.commentsTableView reloadData];
CGRect frame = self.commentsTableView.frame;
frame.size.height = TABLE_CELL_HEIGHT*[commentsArray count];
self.commentsTableView.frame = frame;
CGRect viewFrame = self.contentView.frame;
viewFrame.size.height = viewFrame.size.height + (TABLE_CELL_HEIGHT*[commentsArray count]) + ADD_VIEW_HEIGHT;
self.contentView.frame = viewFrame;
[self.scrollView addSubview:self.contentView];
self.scrollView.contentSize = self.contentView.bounds.size;
}
- (void)createUserInterface {
lblTitle = [[UILabel alloc]initWithFrame:CGRectMake(20.0f, 20.0f, 280.0f, 30.f)];
[lblTitle setBackgroundColor:[UIColor clearColor]];
lblTitle.text = #"Is This Fashion Post";
[self.contentView addSubview:lblTitle];
scrollViewForImage = [[UIScrollView alloc]initWithFrame:CGRectMake(20.0f, 60.0f, 280.0f, 200.0f)];
scrollViewForImage.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
scrollViewForImage.maximumZoomScale = 4.0;
scrollViewForImage.minimumZoomScale = 0.75;
scrollViewForImage.clipsToBounds = YES;
scrollViewForImage.delegate = self;
scrollViewForImage.showsHorizontalScrollIndicator = NO;
scrollViewForImage.showsVerticalScrollIndicator = NO;
//scrollViewForImage.contentMode = UIViewContentModeCenter;
scrollViewForImage.bouncesZoom = NO;
scrollViewForImage.bounces = NO;
//scrollViewForImage.autoresizesSubviews = YES;
[self.contentView addSubview:scrollViewForImage];
imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 280.0f, 200.0f)];
[self.scrollViewForImage addSubview:imageView];
lblBy = [[UILabel alloc]initWithFrame:CGRectMake(20.0f, 270.0f, 30.0f, 20.0f)];
[lblBy setBackgroundColor:[UIColor clearColor]];
lblBy.text = #"By:";
[self.contentView addSubview:lblBy];
lblUploaderName = [[UILabel alloc]initWithFrame:CGRectMake(60.0f, 270.0f, 200.0f, 20.0f)];
[lblUploaderName setBackgroundColor:[UIColor clearColor]];
[lblUploaderName setTextColor:[UIColor blueColor]];
[lblUploaderName setUserInteractionEnabled:YES];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(showUserProfile)];
[lblUploaderName addGestureRecognizer:tapRecognizer];
[self.contentView addSubview:lblUploaderName];
lblOn = [[UILabel alloc]initWithFrame:CGRectMake(20.0f, 300.0f, 20.0f, 20.0f)];
[lblOn setBackgroundColor:[UIColor clearColor]];
lblOn.text = #"on";
[self.contentView addSubview:lblOn];
[lblOn release];
lblDateTime = [[UILabel alloc]initWithFrame:CGRectMake(45.0f, 300.0f, 255.0f, 20.0f)];
[lblDateTime setBackgroundColor:[UIColor clearColor]];
//lblDateTime.text = #"9/11/11 11:09 AM";
[self.contentView addSubview:lblDateTime];
//txtViewComments = [[UITextView alloc]initWithFrame:CGRectMake(12.0f, 330.0f, 280.0f, 70.0f)];
txtViewComments = [[UITextView alloc]initWithFrame:CGRectMake(12.0f, 325.0f, 280.0f, 70.0f)];
//[txtViewComments setBackgroundColor:[UIColor greenColor]];
txtViewComments.backgroundColor=[UIColor clearColor];
[txtViewComments setEditable:NO];
//txtViewComments.text = #"Toronto Film Festival, image from InStyle.com This is a comment on Is This Fashion";
[txtViewComments setFont:[UIFont fontWithName:#"Helvetica" size:17.0f]];
[self.contentView addSubview:txtViewComments];
[txtViewComments setText:[post Comment]];
CGRect frame = txtViewComments.frame;
frame.size.height = txtViewComments.contentSize.height;
txtViewComments.frame = frame;
//newHeight = frame.size.height + 330.0f + 20.0f;
newHeight = frame.size.height + 330.0f + 5.0f;
NSLog(#"newHeight => %f",newHeight);
//btnYes = [[UIButton alloc]initWithFrame:CGRectMake(20.0f, 410.0f, 60.0f, 50.0f)];
btnYes = [[UIButton alloc]initWithFrame:CGRectMake(20.0f, newHeight, 60.0f, 50.0f)];
[btnYes setBackgroundImage:[UIImage imageNamed:#"yes_icon.png"] forState:UIControlStateNormal];
[btnYes setBackgroundImage:[UIImage imageNamed:#"yes_icon.png"] forState:UIControlEventTouchUpInside];
[btnYes addTarget:self action:#selector(btnYesPressed)forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:btnYes];
//***lblYesPercentage = [[UILabel alloc]initWithFrame:CGRectMake(80.0f, 420.0f, 50.0f, 40.0f)];
//lblYesPercentage = [[UILabel alloc]initWithFrame:CGRectMake(80.0f, 420.0f, 70.0f, 40.0f)];
lblYesPercentage = [[UILabel alloc]initWithFrame:CGRectMake(80.0f, newHeight, 70.0f, 40.0f)];
[lblYesPercentage setBackgroundColor:[UIColor clearColor]];
[lblYesPercentage setFont:[UIFont fontWithName:#"Helvetica" size:24.0f]];
//[lblYesPercentage setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"lblYesPercentage.png"]]];
[self.contentView addSubview:lblYesPercentage];
//**btnNo = [[UIButton alloc]initWithFrame:CGRectMake(150.0f, 410.0f, 50.0f, 50.0f)];
//btnNo = [[UIButton alloc]initWithFrame:CGRectMake(150.0f, 410.0f, 60.0f, 50.0f)];
btnNo = [[UIButton alloc]initWithFrame:CGRectMake(150.0f, newHeight, 60.0f, 50.0f)];
[btnNo setBackgroundImage:[UIImage imageNamed:#"no_icon.png"] forState:UIControlStateNormal];
[btnNo setBackgroundImage:[UIImage imageNamed:#"no_icon.png"] forState:UIControlEventTouchUpInside];
[btnNo addTarget:self action:#selector(btnNoPressed) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:btnNo];
//**lblNoPercentage = [[UILabel alloc]initWithFrame:CGRectMake(210.0f, 420.0f, 50.0f, 40.0f)];
//lblNoPercentage = [[UILabel alloc]initWithFrame:CGRectMake(220.0f, 420.0f, 70.0f, 40.0f)];
lblNoPercentage = [[UILabel alloc]initWithFrame:CGRectMake(220.0f, newHeight, 70.0f, 40.0f)];
[lblNoPercentage setBackgroundColor:[UIColor clearColor]];
[lblNoPercentage setFont:[UIFont fontWithName:#"Helvetica" size:24.0f]];
//[lblNoPercentage setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"lblNoPercentage.png"]]];
[self.contentView addSubview:lblNoPercentage];
//newHeight = newHeight + 70;
newHeight = newHeight + 65;
//lblTags = [[UILabel alloc]initWithFrame:CGRectMake(20.0f, 480.0f, 50.0f, 20.0f)];
lblTags = [[UILabel alloc]initWithFrame:CGRectMake(20.0f, newHeight, 50.0f, 20.0f)];
[lblTags setBackgroundColor:[UIColor clearColor]];
lblTags.text = #"Tags:";
[self.contentView addSubview:lblTags];
//newHeight = newHeight - 10;
newHeight = newHeight - 10;
//txtVwTagsValue = [[UITextView alloc]initWithFrame:CGRectMake(65.0f, 470.0f, 220.0f, 90.f)];
txtVwTagsValue = [[UITextView alloc]initWithFrame:CGRectMake(65.0f, newHeight, 220.0f, 90.f)];
//[txtVwTagsValue setBackgroundColor:[UIColor greenColor]];
[txtVwTagsValue setBackgroundColor:[UIColor clearColor]];
[txtVwTagsValue setEditable:NO];
[txtVwTagsValue setFont:[UIFont fontWithName:#"Helvetica" size:17.0f]];
[self.contentView addSubview:txtVwTagsValue];
[txtVwTagsValue setText:[post Tags]];
CGRect frame1 = txtVwTagsValue.frame;
frame1.size.height = txtVwTagsValue.contentSize.height;
txtVwTagsValue.frame = frame1;
[lblTitle setText:[post Title]];
//[btnUploaderName setTitle:[post Username] forState:UIControlStateNormal];
[lblUploaderName setText:[post Username]];
[lblDateTime setText:[post DateAdded]];
//[lblDateTime setText:[self returnDate:[post DateAdded]]];
//[txtViewComments setText:[post Comment]];
[lblYesPercentage setText:[post VoteYes]];
[lblNoPercentage setText:[post VoteNo]];
//[txtVwTagsValue setText:[post Tags]];
// Format the filename
NSString *formattedFilename = [[post Filename] stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
// display image
NSString *url= [NSString stringWithFormat:#"%#%#",PHOTOURL,formattedFilename];
NSLog(#"url %#",url);
if (url !=nil) {
// Here we use the new provided setImageWithURL: method to load the web image
[imageView setContentMode:UIViewContentModeScaleAspectFit];
[imageView setImageWithURL:[NSURL URLWithString:url]
placeholderImage:[UIImage imageNamed:#"Placeholder.png"]];
}
}
-(void)createCommentUserInterface {
//UILabel *lblComments = [[UILabel alloc]initWithFrame:CGRectMake(20.0f, 570.0f, 150.0f, 30.0f)];
//UILabel *lblComments = [[UILabel alloc]initWithFrame:CGRectMake(20.0f, newHeight + 70.0f, 150.0f, 30.0f)];
UILabel *lblComments = [[UILabel alloc]initWithFrame:CGRectMake(20.0f, newHeight + 45.0f, 150.0f, 30.0f)];
[lblComments setBackgroundColor:[UIColor clearColor]];
[lblComments setText:#"Comments"];
[self.contentView addSubview:lblComments];
UIButton *btnAddComment = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnAddComment addTarget:self
action:#selector(btnAddCommentPressed)
forControlEvents:UIControlEventTouchDown];
[btnAddComment setBackgroundImage:[UIImage imageNamed:#"btn_addcomment.png"] forState:UIControlStateNormal];
//btnAddComment.frame = CGRectMake(20.0f, 610.0f, 140.0f, 40.0f);
//btnAddComment.frame = CGRectMake(20.0f, newHeight + 110.0f, 140.0f, 40.0f);
btnAddComment.frame = CGRectMake(20.0f, newHeight + 80.0f, 140.0f, 40.0f);
[self.contentView addSubview:btnAddComment];
//commentsTableView = [[UITableView alloc]initWithFrame:CGRectMake(20.0f, 660.0f, 280.0f, 600.0f) style:UITableViewStylePlain];
//commentsTableView = [[UITableView alloc]initWithFrame:CGRectMake(20.0f, newHeight + 160.0f, 280.0f, 600.0f) style:UITableViewStylePlain];
commentsTableView = [[UITableView alloc]initWithFrame:CGRectMake(20.0f, newHeight + 130.0f, 280.0f, 600.0f) style:UITableViewStylePlain];
commentsTableView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.4];
commentsTableView.delegate = self;
commentsTableView.dataSource = self;
[self.contentView addSubview:commentsTableView];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.commentsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = nil;
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
UIColor *separatorColor = [UIColor colorWithRed:1.0/255.0 green:146.0/255.0 blue:173.0/255.0 alpha:1.0];
[tableView setSeparatorColor:separatorColor];
//[tableView setSeparatorColor:[UIColor darkGrayColor]];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.backgroundColor = [UIColor whiteColor];
userComment = [commentsArray objectAtIndex:[indexPath row]];
UILabel *lblSubmittedBy = [[UILabel alloc]initWithFrame:CGRectMake(10.0f, 5.0f, 100.0f, 30.0f)];
[lblSubmittedBy setBackgroundColor:[UIColor clearColor]];
[lblSubmittedBy setText:#"Submitted by"];
[cell addSubview:lblSubmittedBy];
UIButton *btnUserName = [UIButton buttonWithType:UIButtonTypeCustom];
btnUserName.frame = CGRectMake(120.0f, 5.0f, 150.0f, 30.0f);
//[btnUserName setTitle:#"ITF" forState:UIControlStateNormal];
[btnUserName setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[btnUserName setBackgroundColor:[UIColor clearColor]];
[btnUserName setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[btnUserName addTarget:self action:#selector(showUserProfileForUserComment:) forControlEvents:UIControlEventTouchUpInside];
[btnUserName setUserInteractionEnabled:YES];
[cell addSubview:btnUserName];
UILabel *lblOnDate = [[UILabel alloc]initWithFrame:CGRectMake(10.0f, 40.0f, 20.0f, 30.0f)];
[lblOnDate setBackgroundColor:[UIColor clearColor]];
[lblOnDate setText:#"on"];
[cell addSubview:lblOnDate];
UILabel *lblDate = [[UILabel alloc]initWithFrame:CGRectMake(35.0f, 40.0f, 200.0f, 30.0f)];
[lblDate setBackgroundColor:[UIColor clearColor]];
[cell addSubview:lblDate];
UITextView *txtVwComments = [[UITextView alloc]initWithFrame:CGRectMake(5.0f, 75.0f, 265.0f, 70.0f)];
//UITextView *txtVwComments = [[UITextView alloc]initWithFrame:CGRectMake(5.0f, 75.0f, 265.0f, 0.0f)];
[txtVwComments setBackgroundColor:[UIColor clearColor]];
//txtVwComments.backgroundColor = cell.backgroundColor;
[txtVwComments setFont:[UIFont fontWithName:#"Helvetica" size:17.0f]];
[txtVwComments setEditable:NO];
[cell addSubview:txtVwComments];
[txtVwComments setText:[userComment Comment]];
CGRect frame = txtVwComments.frame;
frame.size.height = txtVwComments.contentSize.height;
CGFloat height = frame.size.height;
NSLog(#"Value of height => %f",height);
txtVwComments.frame = frame;
CGFloat ht1 = height + 20.0f + 75.0f;
//UIButton *btnUpVote = [[UIButton alloc]initWithFrame:CGRectMake(10.0f, 160.0f, 16.0f, 16.0f)];
UIButton *btnUpVote = [[UIButton alloc]initWithFrame:CGRectMake(10.0f, ht1 + 10.0f, 16.0f, 16.0f)];
[btnUpVote setBackgroundColor:[UIColor clearColor]];
[btnUpVote setBackgroundImage:[UIImage imageNamed:#"thumb_up.png"] forState:UIControlStateNormal];
[btnUpVote addTarget:self
action:#selector(btnUpVotePressed:)
forControlEvents:UIControlEventTouchDown];
[btnUpVote setTag:[userComment ID]];
[cell addSubview:btnUpVote];
NSLog(#"Value of ht1 => %f",ht1);
lblUpVoteCount = [[UILabel alloc]initWithFrame:CGRectMake(36.0f, ht1 , 30.0f, 30.0f)];
[lblUpVoteCount setBackgroundColor:[UIColor clearColor]];
[lblUpVoteCount setTag:[userComment ID]];
[cell addSubview:lblUpVoteCount];
//NSLog(#"Value of ht2 => %f",ht2);
//UIButton *btnDownVote = [[UIButton alloc]initWithFrame:CGRectMake(90.0f, 160.0f, 16.0f, 16.0f)];
UIButton *btnDownVote = [[UIButton alloc]initWithFrame:CGRectMake(90.0f, ht1 + 10.0f , 16.0f, 16.0f)];
[btnDownVote setBackgroundColor:[UIColor clearColor]];
[btnDownVote setBackgroundImage:[UIImage imageNamed:#"thumb_down.png"] forState:UIControlStateNormal];
[btnDownVote addTarget:self
action:#selector(btnDownVotePressed:)
forControlEvents:UIControlEventTouchDown];
[btnDownVote setTag:[userComment ID]];
[cell addSubview:btnDownVote];
//lblDownVoteCount = [[UILabel alloc]initWithFrame:CGRectMake(116.0f, 150.0f, 40.0f, 30.0f)];
lblDownVoteCount = [[UILabel alloc]initWithFrame:CGRectMake(116.0f, ht1 , 40.0f, 30.0f)];
[lblDownVoteCount setTag:[userComment ID]];
[lblDownVoteCount setBackgroundColor:[UIColor clearColor]];
[cell addSubview:lblDownVoteCount];
UIButton *btnReply = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//btnReply = [[UIButton alloc]initWithFrame:CGRectMake(180.0f, 150.0f, 60.0f, 40.0f)];
btnReply.frame = CGRectMake(180.0f, ht1, 60.0f, 30.0f);
[btnReply setBackgroundColor:[UIColor clearColor]];
[btnReply setBackgroundImage:[UIImage imageNamed:#"btn_reply.png"] forState:UIControlStateNormal];
[btnReply addTarget:self action:#selector(btnReplyPressed:) forControlEvents:UIControlEventTouchDown];
[btnReply setTag:[userComment ID]];
[cell addSubview:btnReply];
float y = ht1 + 40.0f;
for (int i=0; i < [userComment.replyArray count]; i++) {
if ([userComment.replyArray objectAtIndex:i] != nil) {
UITextView *txtVwReply = [[UITextView alloc]initWithFrame:CGRectMake(5.0f, y , 265.0,0.0f )]; //70.0f)];
//UITextView *txtVwReply = [[UITextView alloc]initWithFrame:CGRectMake(40.0f, y , 220.0,0.0f)];
[txtVwReply setUserInteractionEnabled:NO];
[txtVwReply setBackgroundColor:[UIColor clearColor]];
//[txtVwReply setFont:[UIFont fontWithName:#"Helvetica" size:14.0f]];
[txtVwReply setFont:[UIFont fontWithName:#"Helvetica" size:17.0f]];
[cell addSubview:txtVwReply];
commentReply = [userComment.replyArray objectAtIndex:i];
strReply = [NSString stringWithFormat:#"Submitted by %# \non %#\n%#",[commentReply ReplyUsername],[commentReply ReplyDateAdded],[commentReply ReplyComment]];
//NSLog(#"strReply => %#",strReply);
[txtVwReply setText:strReply];
CGRect frame = txtVwReply.frame;
frame.size.height = txtVwReply.contentSize.height;
CGFloat height = frame.size.height;
NSLog(#"Value of txtVwReply height => %f",height);
txtVwReply.frame = frame;
y = y + height;
//y = y + 80;
[txtVwReply release];
}
}
[btnUserName setTitle:[userComment Username] forState:UIControlStateNormal];
[lblDate setText:[userComment DateAdded]];
[lblUpVoteCount setText:[NSString stringWithFormat:#"%i",[userComment UpVotes]]];
[lblDownVoteCount setText:[NSString stringWithFormat:#"%i",[userComment DownVotes]]];
[lblSubmittedBy release];
//[btnUserName release];
[lblOnDate release];
[lblDate release];
[txtVwComments release];
[btnUpVote release];
[lblUpVoteCount release];
[btnDownVote release];
[lblDownVoteCount release];
return cell;
}
#pragma mark - Table view delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([commentsArray count]>0) {
userComment = [commentsArray objectAtIndex:indexPath.row];
NSString *strComment =userComment.Comment;
//NSLog(#"strComment : - %#",strComment);
NSString *strCommentReply;
CGFloat replyHeight = 135.0f;
if([userComment.replyArray count]>0) {
for (int i=0; i < [userComment.replyArray count]; i++) {
commentReply = [userComment.replyArray objectAtIndex:i];
//NSString *
strCommentReply = commentReply.ReplyComment;
//NSLog(#"strCommentReply => %#",strCommentReply);
// Append all the reply & then use to determine hight
[strCommentReply stringByAppendingFormat:#"\n %#",strCommentReply];
replyHeight = replyHeight + 120.0f;
}
}
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize sizeComment = [strComment sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(sizeComment.height + replyHeight + 40.0f, 44.0f);
NSLog(#"heightForRowAtIndexPath >> height %f",height);
return height;
}
NSLog(#"heightForRowAtIndexPath >> TABLE_CELL_HEIGHT - %f",TABLE_CELL_HEIGHT);
return TABLE_CELL_HEIGHT;
}
So I need to calculate the frame of the table view & accordingly set the frame of table view & content view. How can I do this?
This is how application look like now
Note that your content view is not a subview of your scroll view. If you look at the clip of the interface builder hierarchy, you can see it's on the same level as the other view. I don't know if this is causing your problem, though.
I successfully created a UIscrollview (horizontal) for 50 images and also created a label of "1 of 50" page number displaying at the top of the image along with the scroll view(for example user scroll to next image it would show 2 of 50, 3 of 50, so forth). I am able to display a label at the bottom of the image as a description. My problem is how can I create or code to display different description for each image? Im thinking of NSarray but it shows some random numbers. Is there a sample I can look at to see what I am doing wrong. you can see the description part where I am lost from there. Thanks =)
CGFloat xOffset = 0;
NSInteger pageNumber = 1;
NSUInteger i;
for (i = 1; i <= 5; i++)
{
NSString *imageName = [NSString stringWithFormat:#"creative%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setFrame:CGRectMake(xOffset, 0, 320, 288.5)];
[ourScrollView addSubview:imageView];
[imageView release];
UILabel *pageNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(xOffset, -10, 320, 40)];
[pageNumberLabel setText:[NSString stringWithFormat:#"%d of 5", pageNumber]];
[pageNumberLabel setTextAlignment:UITextAlignmentLeft];
[pageNumberLabel setTextColor:[UIColor whiteColor]];
[pageNumberLabel setBackgroundColor:[UIColor clearColor]];
[pageNumberLabel setFont:[UIFont fontWithName:#"MarkerFelt-Thin" size:18]];
[ourScrollView addSubview:pageNumberLabel];
[pageNumberLabel release];
NSArray *description = [NSArray arrayWithObjects:#"wow", #"bam", #"pow", #"zing", #"bling",nil];
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(xOffset, 250, 320, 40)];
[descriptionLabel setText:[NSString stringWithFormat:#"%#", description]];
[descriptionLabel setTextAlignment:UITextAlignmentLeft];
[descriptionLabel setTextColor:[UIColor whiteColor]];
[descriptionLabel setBackgroundColor:[UIColor clearColor]];
[ourScrollView addSubview:descriptionLabel];
[descriptionLabel release];
xOffset = xOffset + 320;
pageNumber = pageNumber + 1;
You're setting the descriptionLabel with a format of #"%d", which is a decimal format. What is "description"? If it's a NSString then you should be using #"%#".