switch to randomly selected view in xcode - cocoa-touch

utilising xcode using the random function i want to switch to from a view to a randomly selected new view...can some one give me some direction.

A new view (randomly selected) subview of the current view or some view across your application?
For subviews: you could use the tag property of every view, assign a value to it and use viewWithTag: to find a view based on the tag (= the randomly generated number from before).
For views across your app: Why would you want to do something like this? Doesn't sound exactly like good design to me.

Related

Create a Mention friend in iOS with Objective-C

still learning iOS development, want to create something like mention friend likes in Facebook / Instagram.
Mention People UI in Instagram
Is it using new TableViewController and add subview to the same View Controller? (in this case, CommentViewController) , but, when i already have UITAbleViewController in my CommentViewController, how can i handle the second tableviewcontroller?
Looking at the image you provided it looks as though the best way to implement this would be a UIViewController that has a UITableView added to it. Each tableview that is created can have a delegate and datasource set for it. When the textview detects that a mention is being entered (more about detecting this later) you would trigger a second tableview to appear as an additional view (subview) that overlays your current tableview (or as the accessory view of the keyboard, the way apple and others present a textview over the keyboard for text entry ex: messages app).
In order to manage the two tableviews my suggestion would be to create two additional classes each of which conform to the UITableViewDelegate and UITableViewData source. The first one would be the CommentsTableViewManager and the second would be the MentionsTableViewManager. The first tableview would set the CommentsTableViewManager as its delegate and datasource while the second would use the MentionsTableViewManager.
The other problem you may run into later on is determining how to properly detect mentions being typed into the textview. I've actually created an open source library that will help you with this problem. It's located here: https://github.com/szweier/SZMentionsSwift the README should provide enough information for you to get started if you choose to use it.
I hope the information about helps get you started with your app.
From architecture prospective it's way better to have a single table view with altered data source container, depending on current mode.
Speaking an instagram way - either you're showing comments, or, if # symbol was detected, displaying a list of users. So almost all your UITableView's delegate and data source methods will start with something like if (isMentionMode) and you'll choose specific cell class/cell's height/amount of rows per section/etc depends on isMentionMode state.

Mac: Display hierarchical lists of data plus detail view (similar to UINavigationController + UITableViewController)

I am having a serious "best-practice" issue porting my iOS app to the Mac.
I'd like to display a (searchable) list whose entries are either other lists or single entries, for which the user can then show a detail view. Under iOS, this is simply implemented by using a stack of UITableViewControllers for the lists, with another (different) UITableViewController for displaying an entry's details.
However, under OS X, we don't have UINavigationController. It might be possible to implement such a structure via an NSOutlineView or NSBrowser (which are used to display hierarchical data), but I fear that the detail view (which could be implemented as a view on the bottom-most level in the outline view or as the preview controller for the browser) will look out-of-place then. In addition, I'd like to display the list in an NSPopover (as I do on iOS), and placing an NSOutlineView or a NSBrowser inside a NSPopover might look less than elegant.
Any (more-or-less) simple solutions?
I ended up using an NSOutlineView which hierarchically shows all the lists, with a secondary popover (invoked by a button to the right of an entry's cell) for details on the individual entries.

How to duplicate view but in a different page?

I have a view in my app that dynamically creates certain data. I want to be able to create a new view just like the old one, but on a different "page" of the app. Is this possible, and how would I go about doing this? A good example would be the Home Screen on an iPhone. When the number of apps reaches a certain amount on one page, it moves on to the next page and continues putting apps (or in my case data). I have a button that writes objects onto the screen, and stores them in an array. I want it so that when [myArray count] > x, the next object placed will go to another page, but identical to the first one.
Any help would be appreciated!
~Carpetfizz
Things I've tried (that didn't work):
Create an NSObject class that instantiates the view through [myView viewDidLoad], and is activated in myView.
Create a separate view controller that does the same thing as above
You should try using a horizontal UIScrollView (with pagingEnabled set to yes) and a UIPageControl. Check out this tutorial. Another option that creates similar functionality in a little more modern fashion is the UIPageViewController.
Update: I recommend trying out SGPagerView. I just tried it out in the simulator and it looked like a fairly simple implementation.

Using a shared TableView for 3 of my tabs

I want to use the same TableView for 3 of my tabs instead of using 3 identical TableViews. I created three navigation controllers (one for each of the tabs) and linked them to the same Table View Controller But if I run the app with the storyboard like the picture below, it works for the first one of the sharing tabs, but for the other two I get a black screen where the tableView should be. So I want to know if it is even possible to make it work with this setup?
I'm trying this, so I don't have to make a litte change in the tableview 3 times.. The 3 tabs are populated with the same data too, just filtered differently, so just filter the array depending on which parent navigation controller would be simple I suppose.. But I need to know if this is a possible way of sharing view or not.
I would suggest a different approach. Just have three different table views. But since the question is not about being the right approach, I would say that the best way to do it is to do it by code, removing the tableview from the super view (The view controller's view) and moving it to a new view controller when the delegate from the tabbarcontroller is called. Keep in mind that you will also have to assign the delegate and datasource for each view controller.

XCode/Cocoa Mac Changing Views

I'm having trouble figuring out how to change between different custom views in my XCode project.
I have my Main nib file, consisting of 1 main window, and 5 custom views. The main window consists of 5 buttons, all which need to connect to the different views. So for example I click on button 1 and it closes the current menu and loads custom view 1.
I'm having trouble figuring out how this would be done.
I guess I would create IBOutlets for the 5 different buttons and the 5 custom views, and connect them to different methods such as openView1, openView2, where each method would close the current menu and load the custom view?
Could anyone help me code-wise how I would achieve this?
Any help greatly appreciated.
Thanks
So essentially you want a tab view?
You can make an NSTabView in Interface Builder. Set the number of tabs to 5. Then lay out the contents of the views you want inside that.
If you are happy using the standard system provided visual look for your tabs, then you're done. If however you want to have custom buttons that switch tabs, read on.
With your tab view selected, set its style to Tabless:
This makes the tab buttons disappear. That means that switching between views needs to be done through code. First you'll need an IBOutlet that represents your tab view itself: connect that up. Then write an IBAction method for openView1:, that might look something like this:
- (IBAction)openView1:(id)sender
{
[tabView selectTabViewItemAtIndex:0];
}
Make yourself a button (that sits in your window somewhere outside the tab view, otherwise you'd only be able to access it from one tab!) and connect it to this action.
This is probably the easiest way to get going with an interface like this. There's a whole bunch of ways to improve on it depending on how you want to structure your code. For instance, it sounds like you're coming from iOS development, where you'd make a UIViewController for each tab. Well, on the Mac there exists NSViewController, so you can use a similar pattern: but if you do you'll need to write some code that handles getting your view controllers' views into your tab view. It doesn't happen automatically through Interface Builder like it does on iOS. This tutorial should get you started if you choose to go that route.