I need to list set of products in swipe(slide functionality) based on different category, I have used table view to do this, Table view cell count will be number of categories and Single category products in single cell with swipe, center part needs to load based on products in slide(you can check attachment) by clicking left/right arrows or swipe.
Please check below code(added in custom cell implementation file), We believe , struck is due to again and again load of xib. Please suggest some good solution to do this slide functionality inside tableview cell other than using xib or any other suggestion on reuse xib , how to do that?
int xOffset = 0;
self.scrollView.contentSize = CGSizeMake(scrollWidth * noOfImages, scrollHeight);
for(int index=0; index < articleDetails.count; index++) {
UIView *menuOverlay = [[UIView alloc]initWithFrame:CGRectMake(xOffset, 0, scrollWidth, self.scrollView.frame.size.height)];
menuOverlay.backgroundColor = [UIColor clearColor];
SampleXIBView *xibView = [[[NSBundle mainBundle]loadNibNamed:#"SampleXIBView" owner:self options:nil]objectAtIndex:0];
xibView.frame = CGRectMake(35 , 0, scrollWidth-70, scrollHeight);
[menuOverlay xibView];
[self.scrollView addSubview:menuOverlay];
xOffset += scrollWidth;
}
Thanks in Advance.
Related
I'm drawing a view that contains an xib, multiple times (same uiview) and then update the outlets each time it gets drawn displaying an nsmutablearray with different strings on the outlets
Clicking the view opens a viewcontroller that should be displaying the data from the view (+more), this works perfectly fine except it doesn't know which index of the array it's supposed to be displaying.
I'm trying to figure out a way to manage them in a way that I can see which view is being pressed so I can pass that 'id' onto the new vc (something to uniquely identify the view even though it's the same view being drawn)
Here's how the view is being drawn multiple times
- (void) populateUpcoming:(int)events {
[self resetVariables];
upcomingEventsCenterPos = self.view.frame.size.width / 2 - 159;
for (int i = 0; i < events; i++) {
upcomingEventsY2 = 175 * upcomingEvents2;
UIView *firstViewUIView = [[[NSBundle mainBundle] loadNibNamed:#"UpcomingEventFull" owner:self options:nil] firstObject];
[_scrollView addSubview:firstViewUIView];
CGRect frame = firstViewUIView.frame;
frame.origin.y = 9 + upcomingEventsY2;
frame.origin.x = upcomingEventsCenterPos + upcomingEventsX2;
firstViewUIView.frame= frame;
upcomingEvents2++;
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(tapUpcomingEvent:)];
[firstViewUIView addGestureRecognizer:singleFingerTap];
}
[self setupScroll];
}
I think you can use UITableView and custom UITableViewCell for this purpose. On click of "Add More", add one entry to NSMutableArray and just reload tableview.
And no need to manage index separately, you can get it directly by indexPath.row
Also you don't need to manage scroll view size as tableview automatically adjust is content height according to row.
If you are using same kind of view,then go with this approach, as its easy and will save your time.
i want to add 5 views of same size of simulator using UIScrollview. How could i can do? Specially content size of UIScrollview want to set which is approximately equals (320,2840) ?
Looking at your requirement, you need the srollview to scroll vertically as (320,2840)(w,h). While doing this auto layout doesnt create any problem as once your scroll view is set, the 5 views inside id doesnt need to be set via autolayout.
1) First create a Scrollview and set its position on a view. create and IBOutelet for scrollView and then in our viewDidAppear sets its content size to 320,2840 like this
[scrollView setContentSize:CGSizeMake(320, 2840)];
and then create your UIViews in a for loop and add them inside your scrollview with a help a variable say "y" which sets your UIviews y co-ordinate everytime before adding it to your scrollview.
like this
int y = 0;
for (int i = 0; i < 5; i++) {
UIView *insideviews = [[UIView alloc]init];
insideviews.frame = CGRectMake(0, y, 320, scr.frame.size.height);
insideviews.tag = i; // to distinguish them and use later
[scr addSubview:insideviews];
y = y + scr.frame.size.height;
}
thats its, if you still have any problem tell me else you can accept the answer :) Good Luck
I trying to set multiple images from SQL into Table View Cells using
SDWebImage.
I am using this code right now but this loads one image based on a URL.
[cell.imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
How would you populate the imageView for multiple images? Thanks.
I tried using a for-loop. Does not work.
NSArray *itmImageArray = [self itemImages];
for(int i = 0; i <= [itmImageArray count]; i++)
{
[cell.imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/%#",[itmImageArray objectAtIndex:i]]
placeholderImage:[UIImage imageNamed:#"addnewimage.png"]];
}
A UITableViewCell has only one imageView. The technique you are using will keep resetting the same imageView that a UITableViewCell has by default and what you will see is the last image of your for loop set in the cell. If you want to display more images you will have to create a custom cell and add multiple UIImageViews as subviews of the cell. You can then set different images into the UIImageViews you add. Remember, you will have to handle the frames of UIImageViews as well as height of the tableView row so that the content is displayed properly.
I have 2 tables in one view. Table A lists a bunch of users. Table B lists a users objects. When a row is selected in Table A, Table B is reloaded with the objects that belong to that user.
So when a user selects a row in Table A, the image in the background of the cell changes to the highlighted version of the image.
Here is the normal version of the background image:
Here is the highlighted version of the background image:
As you can see, the highlighted version has a small arrow on the right of it. This arrow is beyond the width of the table cell the table itself. When the row is selected, the image changes as it should, but the image is sized down to fit the whole image into the cell.
What I would like to happen is the image goes outside of the table, or on top of the table for that selected row.
One possible solution I thought was to center the table on the selected row and then overlay that image, but if the user was to try to scroll through the table, the image would need to move and that would be a big pain.
So what I would like to know is it is possible to extend the cell's size beyond the table one it is selected?
Thanks in advance!
EDIT:
The following does not work, just in case anyone was going to try:
[cell setFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width+20, cell.frame.size.height)];
Setting a views clipsToBounds property to NO will allow the view to draw outside of its own frame.
In your UITableViewController subclass:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do what you normally do here, if anything then add...
self.view.clipsToBounds = NO;
}
Doing this has a side effect where you will see full cells be created at the bottom or top of the tableview instead of them scrolling partially into view. Either put the table view into another view that has clipsToBounds set to YES, align the edges of the table view with the edges of the screen, or have views covering over the bottom and top (like a UIToolbar and UINavigationBar normally would).
To get the UITableViewCell's selectedBackgroundView to extend past the table view's frame create a subclass of UITableViewCell and override the layoutSubviews method.
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"YQGyZ"]];
self.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"CQXYh"]];
self.textLabel.backgroundColor = [UIColor clearColor];
self.detailTextLabel.backgroundColor = [UIColor clearColor];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect frame = self.selectedBackgroundView.frame;
frame.size.width += 13; // where 13 is the size of the arrow overhang from the same images
self.selectedBackgroundView.frame = frame;
// You can also change the location of the default labels (set their background colors to clear to see the background under them)
self.textLabel.frame = CGRectMake(70, 0, 148, 30);
self.detailTextLabel.frame = CGRectMake(70, 30, 148, 30);
}
Good luck.
I would recommend modifying the image resource of the unselected cell background such that it is the same width as the selected background, but just has a transparent rectangle on the side.
I have a UITableViewController and intend to add a subview to it when I click a button i.e. refresh button. My code is as follows:
//set up loading page
self.myLoadingPage = [[LoadingPageViewController alloc]init ];
self.myLoadingPage.view.frame = self.view.bounds;
self.myLoadingPage.view.hidden = NO;
[self.view addSubview:self.myLoadingPage.view];
My question is how can I set this subview to be in the current visible frame? especially for a UITableviewcontroller where I might click on the refresh button after scrolling down to the 100th cell, for this example, my subview will still be added right at the top of the table view (starting from cell 1). Is there any way to resolve this?
Just move the lines around so that you set the frame after you made it a subview
self.myLoadingPage = [[LoadingPageViewController alloc]init ];
self.myLoadingPage.view.hidden = NO;
[self.view addSubview:self.myLoadingPage.view];
self.myLoadingPage.view.frame = self.view.bounds;