iOS GridView with Sections - objective-c

I am trying to implement my own gridview similar to KKGridView.
My gridview has extra complexity because it needs to support multiple sections with a varying amount of items / cells in each section. (See below)
It also needs to be able to handle moving one cell from section 1 to section 0 and section 0 to section 1.
I have written the UIView to display the grid but it does not support moving cells from one section to another. The question is does anybody have a gridview that supports this functionality or can advise me of the best way forward as this gridview needs to be supported in iOS 5 & iOS 6

I would try using a combination of UICollectionView, with a UICollectionViewFlowLayout along with PSTCollectionView for iOS5 compatibility.
Take a look at the UICollectionViewDelegateFlowLayout docs, I think you'll find everything you need to build a per-section custom layout as you need.
PSTCollectionView is a "open Source, 100% API compatible replacement of UICollectionView for iOS4.3+". Further, you can use UICollectionView on iOS6 and only fall back to PSTCollectionView on iOS5 devices. Take a look at the GitHub project page.
I'm using this approach in one of the apps I'm working on, and it is really simple to implement.
EDIT: The steps you'd take to make what you want would be roughly as following:
You need to download at include the PSTCollectionView in your project. For that follow the steps on the GitHub page.
In your .h file, import PSTCollectionView.h and add the following two protocols: <PSUICollectionViewDataSource, PSUICollectionViewDelegate>. Note that with this you'll use Apple's UICollectionView in iOS6 and PSTCollectionView in iOS5. Here you should also add a property for your collection view: #property (nonatomic, strong) PSUICollectionView *collectionView;
In the viewDidLoad: method, you need to have something like this:
Code:
PSUICollectionViewFlowLayout *flowLayout = [[PSUICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[flowLayout setItemSize:CGSizeMake(91, 119)];
[flowLayout setMinimumLineSpacing:0];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
And you'd need to implement the following methods to your liking:
Methods:
numberOfSectionsInCollectionView:
collectionView:numberOfItemsInSection:
collectionView:cellForItemAtIndexPath:
collectionView:layout:insetForSectionAtIndex:
collectionView:layout:minimumLineSpacingForSectionAtIndex:
collectionView:layout:minimumInteritemSpacingForSectionAtIndex:
Important: Don't forget to prefix every mention of UICollectionView classes with PS. For example PSUICollectionView or PSUICollectionViewLayout.
EDIT 2: For a general understanding of UICollectionView refer to this excellent tutorial.

You can use you custom cells to achieve this functionality. One Cell with 10 subViews and 2nd with 6 subView. It will work for you.
you can get the view in the cell by tags i.e 1-6 and 1-10
Try this

Related

How to check what frameworks and methods supported by winobjc

I tried to port a sample iOS app with a UITableView to Windows 10. In which it tries to display 100 rows with each row contains label with value as row number. Here is the code
UILabel *label = (UILabel*)[cell viewWithTag:1];
label.text = [NSString stringWithFormat:#"Name %ld", indexPath.row];
And when launched this app in windows10 i see only empty rows.
Does viewWithTag is supported?.
How do i check what api's and methods supported by winobjc? Is there any documentation available on this?
I work on the iOS bridge project at Microsoft. The problem you're seeing here has to do with cell reuse identifiers, not viewWithTag. Our Xib2Nib tool handles converting Storyboards and Xibs when you run vsimporter. Currently, Xib2Nib does not support cell reuse identifiers defined in Storyboards (although it does support cell reuse identifiers in Xibs). So when you call dequeueReusableCellWithIdentifier:forIndexPath:, the correct cell with your UILabel in it is not instantiated, which results in you getting blank cells.
There are a couple of potential solutions to this. You could build your layout programmatically in a UITableViewCell subclass and use registerClass:forCellReuseIdentifier:. You could also lay out your cell in its own xib file (separate from your Storyboard) and use registerNib:forCellReuseIdentifier:.
In either case, you should file an issue on the project on Github if you'd like to see support for cell reuse identifiers in Storyboards – Github is the best way to get in touch with our team and informs all of our prioritization decisions.
More generally, you can see what's supported and not supported by the bridge in the Visual Studio debug console; when missing or stubbed APIs are called, you'll get a message with details. We're also working on tools that will make browsing the API surface area easier.
Thanks for checking out the project!

ios 8 change the size of presented/modal view controller

In ios 7 and before, I was updating the bounds of presentedViewController.view.superview to custom the size of presented view controller, but it seems this would not be the case in ios 8 any more. Since there is no superview can be set on the view controller(return nil when you try to call it in debugger).
Any suggestions how to update the presented view controller's size? This would be used for the custom presentation transition.
I guess the following is easier and it works in iOS 8:
self.myViewController.modalPresentationStyle = UIModalPresentationFormSheet;
self.myViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//This will be the size you want
self.myViewController.preferredContentSize = CGSizeMake(822, 549);
[self presentViewController:self.myViewController animated:YES completion:nil];
In case anyone runs into this later, here is how I solve it.
Subclass the UIPresentationController and return the frame in frameOfPresentedViewInContainerView. Feed this into the transitioningDelegate that you create for the presentedViewController.
Or, you may set the final frame for the presentedView in the animateTransition:, which belongs to the animator object you created for transitioningDelegate. However, this is the old iOS 7 way of doing it. Since Apple introduce UIPresentationController, any size/frame changes should be done there instead, which is the previous method I mentioned.
Here are some extra information that may not be directly related to solving the problem.
For those of you who never got your hands on the apple view controller transition api, just like me before, here are the steps.
Create YourTransitioningDelegate, which conforms UIViewControllerTransitioningDelegate. In here, generally three things need to be set, PresentationController, PresentedAnimationController, DismissedAnimationController.
Create YourTransitionAnimator, which conforms UIViewControllerAnimatedTransitioning. Here, two functions need to be override, transitionDuration and animateTransition(This is where all the animation happens, adding/removing and animating the presentedView. Make you call completeTransition on transitionContext to end the animation).
Subclass UIPresentationController. Depends on each individual needs, you may do a ton of things here. I just added a dimmingView and changed the frame of presentedViewController.
Finally, hook things up before presenting the view controller, which is changing the modalPresentationStyle to be custom and setting the transitioning delegate.
Things I found really helpful, two 2014 WWDC videos("View controllers advancements" and "A look inside presentation controllers") and the sample project from Apple(LookInside-photoEditingApp).
Instead of subclassing you can use the preferredContentSize property
- (void)viewDidLoad {
[super viewDidLoad];
self.preferredContentSize = CGSizeMake((self.view.frame.size.width / 100) * 65, (self.view.frame.size.height / 100) * 65);
}

iOS7 Strange behavior of UIPickerView with an UIImage as custom view, any official info?

I was following a tutorial on how to build a custom picker with an UIPickerView in Sams Teach Yourself IOS6 Application Development in 24 hours and I've noticed that simply returning an UIImage in (UIView*)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view method of the UIPickerViewDelegate does not work properly: the images do not appear correctly (they rotate on the spinning wheel but for example they disappear when they should move over the current selection's row). I've found a solution at this link on Stack Overflow and it effectively works, but I'd like to know if this strange behavior appeared in IOS 7 is due to a new way of using UIPickerView or if it is more a sort of bug.. I did not find anything useful in the official API Reference docs. Is there any official doc that is talking about the change in how we must return an UIImageView to be used in a UIPickerView
It looks like the answer is 'No'. I also looked through the Release Notes for 7.0 & 7.1 and looked at the differences in the references for UIPickerView, UIPickerViewDelegate, and UIView (among others) and couldn't find anything do explain why it behaves this way now and I couldn't find any changes to UIPickerView or anything it inherits from or conforms to that would explain it. (If there is something there that explains it then it was not immediately obvious to me.)
As far as I know, those are the only places that would have any official information on this.
I think the only way to know for sure whether this is deliberate or a bug is to report it.

UIScrollView does not scroll when an object is inside

I made a UIScrollView inside a UIViewController I have like 5 ViewControllers my problem is in the 4th one.
The UIScrollView I made does scroll when I put notting it it (so no label no button, no objects at all) but when I put even a label (or anything) in the UIScrollView it stops working.
Edit:
I have try'd making the same thing in a new project, for some reason it does work I think it has something to do with the fact that it is in the 4th ViewController and the new one I made, was made, in the First automatically made viewcontroller.
I do not yet have a answer please help.
My code:
viewcontroller.h
#import <UIKit/UIKit.h>
#interface viewcontroller : UIViewController
#property (weak, nonatomic) IBOutlet UIScrollView *ScrollerMdon;
#end
viewcontroller.m
#synthesize ScrollerMdon;
- (id)initWithNibName:(NSString *) nibNameOrNil bundle:(NSBundle *) nibBundleOrNil
{
self = [super initWithNibName: nibNameOrNil bundle:nibBundleOrNil];
if(self)
{
}
return self;
}
-(void)viewDidLoad
{
[ScrollerMdon setScrollEnabled:YES];
[ScrollerMdon setContentSize:CGSizeMake(320,1000)];
[super viewDidLoad];
}
#end
In xcode viewcontroller connection inspector my outlet ScrollerMdon is connected with *Scroll View(*which I inserted in my viewcontroller)
In xcode UIScrollView connection inspector my Referencing outlet ScrollerMdon is connected with viewcontroller.
Please help me I have been trying to solve this for 5 hours.. I can't stand it anymore.
Edit:
I try to make it possible for a single viewcontroller to hold like 17 textboxes I see no other way than doing it with a UIScrollView if there are any suggestions I would be really happy.
Edit2:
I have try'd to make it all aggain putting the same class on a different view controller and the other way around, I kinda rewrote the code and everything it's exactly the same as what I made in the other project but it does not work.(when an object is inside..)
2 foto's of my program.
Srry for the small and bad images, for some reason they moved without my permision but it is enough information I guess.(I use VMWare 8 with os x leopard on it)
foto 1
foto 2
Me Scrolling without items:
imgur.com/cd16I
Me desperately Scrolling with items:
imgur.com/hNUl1
Since I can only post 2 hyperlinks you have to open these yourself.
PS. please upvote this if you do not know the answer for I need a answer and there will probably be more viewers if it gets upvoted, ty.
Edit3:
I am now copying my entire code and build of the app in a different project hope this wil work :S.
I had the SAME exact problem that I ran into yesterday. Drove me nuts for hours... This was a brand new project that I just started like a week or so ago.
The thing is, I had another project that had the exact same setup essentially that I had started last summer that has no problems. Tabbed application, VC that has a UIScrollView with many uiviews, labels, images etc... works great.
So what changed from that project to this project? The version of Xcode that I started the project out in. The project from last summer did NOT have the AutoLayout enabled as an option. This new one did ( Xcode 4.6 ).
If I turn off "Use AutoLayout" for the entire project it works fantastic.
In the Utilities panel, click on the File Inspector tab. In the section for "Interface Builder Document" you'll see a checkbox for "Use AutoLayout". De-select that and re-build your app. Just found this trick not more than 10 minutes ago for my own project -- works great.
Hope this works for your project... good luck!
I found the solution it might not be the perfect solution but it works.
The problem seemed to be somewhere in my first project since I could make it work in other projects,
so I copy'd my entire project to a different project and this way it worked.
This solution won't explain what is wrong but I think it will solve your problem.
Copy the elements from the new project you created to the old one and replace the affected view controller. Copy also the class.
There must be something wrong with your connections but with the info you provided is impossible to check.
If that doesn't work then it must be something in the navigation (doubt it) or in some custom code you have on the class (very difficult if all the code you have is in the viewDidLoad as you've shown).

Can anyone help out an Objective C novice?

I feel i am totally out of my depth here, im very new to objective c but have been asked to design an iphone app as part of my uni course. I designed a sinple quiz before, but I was hoping to design a more advanced quiz game with 3 levels (each level will have a different quiz).
I dont know how to use the UIViews and I have tried a tutorial online to help me code a navigation controller. It allows gives me 3 options to go into subview 1, 2 or 3. All the subviews have the same screen though, with one label and a button.
I have 3 classes so far, RootViewController, BasicNavigationAppDelegate and SubViewOneController.
I really dont understand the code at all, im familiar with Java but this objective c is nothing like it. Could someone maybe take a minute to help out a person in distress and explain if i am doing this right by using the navigation controller to display my levels? When i check the xib interface files i dont see the button or label, or dont know where to add the quiz interface objects!! I really am confused by all this. Could anyone help?
You should search google for sample source code, and see how some of the views can be handled. There are many ways you can handle a view, whether its by a UINavigationController, UITabBarController, etc. If you are new to Objective-C, then your not really going to get an answer to this question that will instruct you on what exactly to do.
Interface Builder + View Controllers
Here's a good one for you: View Controllers Programming Guide
(Apple's) View Controller Reference Guide
Some Code Samples
Getting Started Sample Code
I recommend Head First iPhone Development: A Learner's Guide to Creating Objective-C Applications for the iPhone. Within a few chapters you'll know everything you need to build this app and you'll actually understand what you're doing.
(I don't know the authors or the publisher, I just think it's a great book for quickly getting up to speed.)
for a 3 level quiz, UINavigationController is definitely an option.
if you need to find out how to use a class, in xcode, type its name, then press -alt- and double click the class name, this will bring up a short description, with two icons, one will take you to the header file, and the other to the documentation.
to add elements to the nib/xib files, you will need to open the library window, where you will find labels, buttons etc. to use a button, you will need to define an action in your header file, and hook it up in IB, to be able to interact with UIElements in your code, you want to set up outlets in the header file, and hook them up in IB.
something you need to decide on, is how you are going to present the questions, and will also depend if the answer will be true/false, multiple choice, or text entry.
if you arent familiar with obj-c and xcode, it is probably worth picking up an ebook from someone like http://www.pragprog.com. they have an iPhone one up there by Bill Dudney which is quite good(i believe he now works for apple.)
for the standard slide out transition you could use this.
//you would probably want to call this something like level1NavBarItemWasPushed: instead
- (IBAction)lvl1pushNavBarItem:(id)sender {
//create instance of AnswersViewController class.
AnswersViewController *level1AnswersVC= [[Level1AnswersViewController alloc] init];
//pass it some kind of identifier so it can tell which quiz/question it is dealing with and pull in the answers, so that you can reuse the view
[level1AnswersVC setAnswersObject:<<insert object dictionary here>>];
//push the view controller onto the navigationController's view stack
[self.navigationController pushViewController:level1AnswersVC animated:TRUE];
//pushing it onto the view stack has given it +1 retain, so we can now release it without worrying about it disappearing prematurely.
[level1AnswersVC release];
}
for the page flip transition you could use this.
- (IBAction)lvl1pushNavBarItem:(id)sender {
//create instance of AnswersViewController class.
AnswersViewController *level1AnswersVC= [[Level1AnswersViewController alloc] init];
//pass it some kind of identifier so it can tell which quiz/question it is dealing with and pull in the answers, so that you can reuse the view
[level1AnswersVC setAnswersObject:<<insert object dictionary here>>];
//set the current viewController as the delegate, so that it can call back to us when its done
level1AnswersVC.delegate = self;
//set the modal transition style
level1AnswersVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//show answers as modal view, which has been setup to use the page flip transition.
[self presentModalViewController:level1AnswersVC animated:YES];
//pushing it onto the view stack has given it +1 retain, so we can now release it without worrying about it disappearing prematurely.
[level1AnswersVC release];
}