I test an application on iOS8 which works well on iOS7. It seems that the function "scrollToItemAtIndexPath:atScrollPosition:animated:" doesn't work on iOS8.
This is my function which used it.
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if([collectionView isEqual:m_CollectionViewSequence])
[m_CollectionViewSequence scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
}
Related
I'm trying to get a UICollectionViewCell to do an animated resize and at the same time have the collection view scroll the cell to the top of the collection view's viewport.
When I do
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop animated:YES];
[collectionView performBatchUpdates:nil completion:nil];
}
with
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
if (cell.isSelected) {
return self.collectionView.frame.size;
}
else {
return CGSizeMake(300, 100);
}
}
the scroll happens before the resize animation.
And if I call scrollToItemAtIndexPath inside of performBatchUpdates like
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[collectionView performBatchUpdates:^{
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop animated:YES];
} completion:nil];
}
it doesn't work most of the time.
Thanks!
-Eric
The best way to achieve an effect like this is to simply subclass UICollectionViewFlowLayout and tweak cell layout attributes based on the selected cell.
I have some issues in Today Extensions on iOS8. I tried debugging using the Xcode Debugger and by putting nslogs. There is no logic in my code as well. For some reason:
The widget is not displaying any data (its only working for Hello World Label)
Debugging is not working, it doesn't reach any break points. Is there any specific way to debug extensions?
Here is my code snippet
#implementation TodayViewController{
NSArray *localList;
}
-(void)awakeFromNib{
[super awakeFromNib];
[self loadList];
[self setPreferredContentSize:self.tableView.frame.size];
NSLog(#"inside awake from nib");
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(#"inside view did load");
}
-(void)loadList{
NSMutableArray *mutableArray = [[NSMutableArray alloc]initWithCapacity:5];
[mutableArray addObject:#"asdjasdj"];
[mutableArray addObject:#"qowiepqiw"];
[mutableArray addObject:#"qoqwoei"];
[mutableArray addObject:#"pqoiweoqi"];
[mutableArray addObject:#"lkdsflk"];
[mutableArray addObject:#"kdjlkaj"];
localList = [mutableArray copy];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [localList count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"WidgetCell"];
UILabel *label = [[UILabel alloc]init];
[label setText:[localList objectAtIndex:indexPath.row ]];
[[cell contentView]addSubview:label];
return cell;
}
Write this
[self setPreferredContentSize:self.tableView.frame.size];
before loading any subview (tableview or label), and I write these in viewDidLoad. It works for me.
If the widget is not displaying, you can also try rebooting the phone.
To debug the extension, you need to manually attach the widget to the debugger.
From the Xcode menu "Debug" -> "Attach to process" -> "your extension bundle id"
Also make sure that the phone is unlocked if you're running it on a device. At least for me running the widget target won't unlock the phone but it works just fine if I do it myself.
So I have use tableview to make a list that works with the search bar, but now I want the sections in the tableview to navigate/go to a new view/page/screen when I press it, can anyone help me with this?
Here you go:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[self navigationController] pushViewController:[[SecondViewController alloc] initWithNibName:#"SecondView" bundle:[NSBundle mainBundle]] animated:YES];
}
I just started using xcode and OBJ-c this year.
I am using mwfeedparser for a app I'm making but would like to change the look of the detailview.
right now i'm using the demo app that came with mwfeedparser to change the detail view.
i would like the detail view to have labels instead of being a tableview
i have changed this code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detail = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
detail.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detail animated:YES];
// Deselect
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
when i run the code the detailview doesn't even come up. am I doing something wrong?
thanks for your help.
btw when i do get this done I'll put it up on github incase anybody else needs it
enter code hereself.parsedItems = [[NSMutableArray alloc] init];
- (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item{
if (item) {
[self.parsedItems addObject:item];
}
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detail = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
detail.item = [self.parsedItems objectAtIndex:indexPath.row];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detail animated:YES];
}
this is my first post so please be gently.
I am using the basic Split View-based application within xcode, but have edited it so that the rootViewController does not simply update the detailViewController, but instead pushes a new UITableViewController (taskViewController) onto the navigation stack.
My problem is, that nothing happens when I now call the following from my taskViewController:
detailViewController.detailItem = [NSString stringWithFormat:#"Row %d", indexPath.row];
If I call this from rootViewController, instead of pushing a new UITableView onto the stack, it works.
Here is my code from rootViewController when a cell is selected:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TaskViewController *taskViewController = [[TaskViewController alloc] init];
taskViewController.title = [NSString stringWithFormat:#"Unit %d",indexPath.row];
[self.navigationController pushViewController:taskViewController animated:YES];
[taskViewController release];
}
Have I done something wrong here? Am I using the navigation controller correctly within the rootViewController of the UISplitViewController?
Your rootViewController can access detailViewController because it has a referance to it. if you push a new controller onto the nav stack, then its not automatically going to know about DetailViewController.
Have you NSLog'd detailViewController in your taskVC to see if it has a pointer?
You would typically set this when you are creating it like this:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TaskViewController *taskViewController = [[TaskViewController alloc] init];
taskViewController.title = [NSString stringWithFormat:#"Unit %d",indexPath.row];
taskViewController.detailViewController = self.detailViewController;
[self.navigationController pushViewController:taskViewController animated:YES];
[taskViewController release];
}