iOS Popover and tableviewcontroller refreshing issue - ios

I'm writing a project that simulates a Master/detail layout for iPad.
So i've a masterView(UITableView), a detailView(UICollectionView), a global Navigation Bar and a TabBar.
The tabbar is filled with some catecories i need to choose from and the masterview is filled according to the tabbaritem selected.
In landscape mode, when both master and detail view are shown, everything works fine.
In portrait mode, my master view is hidden and i've got a button that open a popupcontroller with my master in it. The problem is that this popup doesn't seems to show the changes made on the masterview content
the MasterView is a UITableViewController.
I've correctly implemented the delegate and datasource method.
Here is the code to open/dismiss the popover
if(myPopIsVisible)
{
myPop = [[UIPopoverController alloc]initWithContentViewController:myMasterView];
[myPop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
myPopIsVisible = YES;
}
else
{
[myPop dismissPopoverAnimated:YES];
myPopIsVisible = NO;
}
Checking in debug it lend me to the correct content of myMasterView (number and content of rows) but it only show the first one loaded by the app.
I'm using ARC...
This is myMasterView class implementation
#implementation myMasterView{
NSArray *cellTitles;
NSArray *cellIco;
NSArray *cellTag;
}
- (void) setData:(NSArray *)titles :(NSArray *)icos :(NSArray *)tags
{
cellTitles = titles;
cellIco = icos;
cellTag = tags;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if(cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
// Configure the cell...
cell.textLabel.text = [cellTitles objectAtIndex:indexPath.row];
cell.tag = [[cellTag objectAtIndex:indexPath.row] integerValue];
#warning icona non impostata
// cell.imageView.image = [cellIco objectAtIndex:indexPath.row];
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [cellTitles count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(isPopover)
{
isPopover = NO;
[master dismissPopoverController];
}
}

Related

UITableView does not load data

I am relative new to iOS development. Right now, I created 2 ViewController using storyboard. The one consist one button that lead into another controller using segue (show).
This controller is TableViewController that embedded in Navigation Controller and already connected with its responsible class that inherit from UITableViewController.
My problem is this page doesn't load its data (NSMutableArray) that already initialized in viewDidLoad using
_dataClient = [NSMutableArray arrayWithObjects:#"First City",#"Second City",#"Third City",#"Forth City",#"Fift City", nil];
This is my table delegate and datasource:
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_dataClient count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = #"cellItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
// Configure the cell...
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [_dataClient objectAtIndex:indexPath.row];
return cell;
}
Is there any step that I forgot to do?
You must return 1 section at least. Change this line:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; /// here
}

UITableview tries to scrollToTop but doesn't (Indicator tries to go up, strange.) - video

So I've been working on a UITableView and I can't hit the statusbar to scroll up, however it seems like it's trying to scroll up, but it doesn't.
Here you can see a video of it (Decided to use mp4 instead of GIF since it was so laggy)
http://i.gyazo.com/4c7be7437116e420411ac879b6d0d784.mp4
If you look at the video you can see that you indicator on the right side tries to scroll up but doesn't ? Has anyone experienced something similar ?
I'm also using ECSlidingViewController
My current code
Called upon -viewDidLoad
-(void)setTableViewStuff {
[self.myTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.myTableView registerNib:[UINib nibWithNibName:#"YouTubeTableCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
self.myScrollView.scrollsToTop = NO;
self.myTableView.scrollsToTop = YES;
}
Table View Code
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 256;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return myVideoTitles.count;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
YouTubeTableCell *cell = (YouTubeTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
//cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if (indexPath.section == 0) {
NSString* thumbnailURL = myVideoThumbnails[indexPath.row];
[cell.myThumbnail setImageWithURL:[NSURL URLWithString:[thumbnailURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:nil];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
EDIT:
Found a solution to this!!, Apperiantely if you're using ECSlidingViewController you must have yourtableview.scrollstotop = NO; inside the "drawer"
Found a solution to this!!, Apperiantely if you're using ECSlidingViewController you must have yourtableview.scrollstotop = NO; inside the "drawer"

A uitable view with 3 groups in it

i am a developing a ios app with a view controller and a table view in it. i am trying to load list of items in 3 groups but when i compile it it shows correct count but not showing all the items jus repeating items. please help. let me post my code here.
#interface ViewController ()
#end
#implementation ViewController {
NSArray *menuItems;
NSArray *menuItems2;
NSArray *dash;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithWhite:0.6f alpha:1.0f];
self.tableView.backgroundColor = [UIColor colorWithWhite:0.6f alpha:1.0f];
self.tableView.separatorColor = [UIColor colorWithWhite:0.15f alpha:0.2f];
menuItems = #[#"itm1", #"itm2", #"itm3", #"itm4"];
menuItems2 = #[#"itm1", #"itm2", #"itm3", #"itm4"];
dash = #[#"itm1", #"itm2"];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if (section == 0) {
return [menuItems count];
}
if (section == 1) {
return [menuItems2 count];
}
if (section == 2) {
return [dash count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
#end
Your cellForRowAtIndexPath... method needs to be written so the cell is populated with proper data based on the cell's section and row. Right now you don't do anything but use an empty cell.
You don't configure your cells. After dequeuing a cell, you have to set its title.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Get the correct array, depending on the current section.
NSArray *items = nil;
if (indexPath.section == 0) {
items = menuItems;
}
else if (indexPath.section == 1) {
items = menuItems2;
}
else if (indexPath.section == 2) {
items = dash;
}
// Get the string from the array and set the cell's title
NSString *title = items[indexPath.row];
cell.textLabel.text = title;
return cell;
}

My table view is loading the detail view in a dark screen

So i have a table view hooked up to a plist with urls. When I click on the table view cells i want it to take me to the detail view, but the only problem right now is when i click on the cell to take me to the detail view it just loads a dark screen with nothing on it. I don't receive any errors on the compiler so i have no idea what is wrong. I have reset the stimulator and tried restarting my computer but now I'm starting to think there is something wrong with the code. Can someone help?
TableViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
NSString *myListPath = [[NSBundle mainBundle] pathForResource:#"myList" ofType:#"plist"];
tableData = [[NSArray alloc]initWithContentsOfFile:myListPath];
NSLog(#"%#",tableData); }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [tableData count]; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if( cell == nil )
{
NSLog(#"Cell Creation");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"cell"];
}
//Set Data For each Cell
cell.textLabel.text = [[tableData objectAtIndex:indexPath.row]objectForKey:#"cellName"];
cell.detailTextLabel.text = [[tableData objectAtIndex:indexPath.row]objectForKey:#"cellSubtitle"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"Index Selected,%d",indexPath.row);
WebViewController *View = [[WebViewController alloc] init];
NSString *urltoPass = [NSString stringWithString:[[tableData objectAtIndex:indexPath.row]objectForKey:#"cellSubtitle"]];
View.urlString = [[NSString alloc] initWithFormat:#"http://%#",urltoPass];
View.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:View animated:YES completion:nil];
}
When you make a controller in a storyboard, you need to get an instance of that view controller by using instantiateViewControllerWithIdentifier:, not by using alloc init.
WebViewController *View = [self.storyboard instantiateViewControllerWithIdentifier:#"WebView"];
In the storyboard, you need to give the controller the identifier "WebView".

iOS: uitableview redraw objects on first cell to bottom cells

i have a uitableview with custom cells.. with normal code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
DDMainCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil)
{
cell = [[DDMainCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
}
the problem is when i select one cell i add progress bar on the cell that download data online.. but when i Scroll down i find that every 10 cells have the same progress bar .. how can i prevent this behavior ?
Try this,
- (void)viewDidLoad
{
[super viewDidLoad];
dataarr=[[NSMutableArray alloc]init];
indexarr=[[NSMutableArray alloc]init];
mytableview=[[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
mytableview.dataSource=self;
mytableview.delegate=self;
[self.view addSubview:mytableview];
for (int i=0; i<30; i++) {
[dataarr addObject:[NSString stringWithFormat:#"%d",i]];
}
// Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [dataarr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
}
cell.textLabel.text=[dataarr objectAtIndex:indexPath.row];
UIActivityIndicatorView *act=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[act setFrame:CGRectMake(50, 20, 20, 20)];
act.hidden=YES;
[cell.contentView addSubview:act];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
if ([indexarr containsObject:[dataarr objectAtIndex:indexPath.row]])
{
[act startAnimating];
act.hidden=NO;
return cell;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexarr containsObject:[dataarr objectAtIndex:indexPath.row]])
{
[mytableview reloadData];
return;
}
[indexarr addObject:[dataarr objectAtIndex:indexPath.row]];
[mytableview reloadData];
}
Make sure, when downloading is complete, then remove this object from indexarr....
That's because your cells are getting reused; UITableView will put off-screen cells into the reusable cell queue, and dequeue them for reuse if the reuseIdentifier matches. You should use some other data structure (e.g. NSArray or NSDictionary) to track which indices/cells have already been tapped. Then, in the method you showed above, regardless of whether the cell was init-ed or dequeued, set the progress bar according to your underlying data structure.
Here your used UITableViewCellIdentifier is reuseIdentifier. Which will work for all Cells are same type. Now your are taking once cell with progress bar. Now it will different from all cells data.
So use one more tableview cell for progress bar, or while reloading table remove the Progress bar which is exists already and add again. for this use tag for progress bar.

Resources