How can we show only specific no. of view in iCarousel, if we have 'n' no. of views? - icarousel

Actually, I have 5 views in iCarousel, it displaying all the five views, but I need to show only 3 views instead of 5 views how can i achieve this scenario?

Override this function in your ViewController to specify the number of items
// ViewController.m
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
//return the total number of items in the carousel
return 3;
}
Make sure the ViewController is set as the delegate and datasource
// ViewController.h
#interface ViewController : UIViewController <iCarouselDataSource, iCarouselDelegate>

Related

Passing data to another view controller in swift 3

How do I send coredata values when selecting a row in table view to another view controller using SHOW SEGUE in swift 3?
This is my code in objective c using Present Modally Segue and I want the equivalent of that code in swift 3 using Show Segue because I'm using a navigation controller. I've been working on this for a couple hours but as of now, I still haven't been able to do it.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"UpdateDevice"])
{
NSManagedObject *selectedDevice = [self.accounts objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
detailViewController *destViewController = segue.destinationViewController;
destViewController.account = selectedDevice;
}
}

How to TDD a UITableViewController (using storyboards)

I'm getting started with TDD and got stuck testing a simple UITableViewController (using storyboards).
The tableView should have one row for every element in my model NSArray:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.sortedStories count];
}
My test for this is:
- (void)testTwoStoriesShouldLeadToTwoRowsInSectionZero
{
_sut.sortedStories = [self arrayWithTwoStories];
[_sut.tableView reloadData];
XCTAssertEqual([_sut tableView:_sut.tableView numberOfRowsInSection:0], 2, #"The number of rows should match the number of stories");
}
And I'm initializing my _sut in my test class from my storyboard like this:
- (void)setUp
{
[super setUp];
UIStoryboard *storyboard =
[UIStoryboard storyboardWithName:#"Main_iPhone"
bundle:nil];
_sut = [storyboard instantiateViewControllerWithIdentifier:
#"MyTableViewController"];
}
This works perfectly fine if there is no setup of the model in my production code. But after I added this default setup with seven stories in my UITableViewController's viewDidLoad method:
- (void)viewDidLoad
{
[super viewDidLoad];
self.sortedStories = [self sevenDefaultStories];
}
the test suddenly fails, stating that 'seven isn't equal to two'. The tableView seems not to reload the data, though I have the [_sut.tableView reloadData] in my test after changing the model.
What am I doing wrong?
I found it:
Though the tableViewController was instantiated via storyboard etc., the view had not been loaded yet!
So viewDidLoad also had not been called yet, when I 'changed' my model. But then, when I called [_sut.tableView reloadData] (which should make sure, the tableView would get synced with my model), this caused exactly the opposite: accessing the tableView made it necessary that the view got loaded, so NOW finally viewDidLoad was called on my tableViewController! And so my model got changed again, overwriting my nice test model with default values.
The solution was, to add [_sut view]; to the top of my test case. This makes sure that the view is already loaded when my test begins.
And, in my case, calling [_sut.tableView reloadData] wasn't necessary at all, since I'm only testing the dataSource method directly, not the actual tableView. N.B.:[_sut view] still needs to be called, because the dataSource method in my XCTAssertEqual() statement also triggers the view to be loaded, if that has not happened yet.
So the working test case looks like this:
- (void)testTwoStoriesShouldLeadToTwoRowsInSectionZero
{
[_sut view];
_sut.sortedStories = [self arrayWithTwoStories];
XCTAssertEqual([_sut tableView:_sut.tableView numberOfRowsInSection:0], 2, #"The number of rows should match the number of stories");
}
During test setup (my preferred solution):
[UIApplication sharedApplication].keyWindow.rootViewController = _sut; // Suck it UIKit
You may alternatively consider:
[[UIApplication sharedApplication].keyWindow addSubview:_sut.view]; // Hax
Note that UITableView may not render any cells unless it has been added to the view hierarchy. Similarly, UIViewController lifecycle methods may not be called unless it is added to the view controller hierarchy. I currently use "my preferred solution" above because it accomplishes both.

iOS 5 Storyboard: NavigationViewController to TabbarController - Not working , Why?

I am using iOS5 with Storyboard and my scenes are like this :
NavigationCOntroller ->(Nav view 1) TableViewController -> TabBarController ->(Tab1)TableViewController
and similarly I more tabs under my TabBarController.
Now I go to Tab1 when user clicks on any row in my TableViewCOntroller and before PerformingSegue I want to send some data to my Tab1(TableViewController) like this
MyTableVController *tvc = segue.destinationViewController;
tvc.selectedObject = currentObject;
[UITabBarController setSelectedObject:]: unrecognized selector sent to instance 0x68c9450
Now why is it assuming that 'MyTableVController' is a UITabBarController and searching for setSelectedObject method ???
And how can I pass data to my TableViewCOntroller in this scenario ?
Thanks.
OK I have found solution to my problem , I did like this
UITabBarController *tabController = (UITabBarController *)segue.destinationViewController;
MyTableVController *tvc = (MyTableVController *)[viewControllers objectAtIndex:0];
And thats how you have your required viewcontroller and pass data to it.

How to pass data viewcontroller via Tab bar Controller

I want to pass datum from view controller to view controller via tab bar controller.
I mean, my storyboard is like this.
View Controller → Tab Bar Controller → VC1/VC2/VC3
For the purpose of this, I tried to use PrepareforSegue, but it's failed.
The code is here.
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
friendsDetailViewController* vc = [[friendsDetailViewController alloc] init];
vc = (friendsDetailViewController*)[segue destinationViewController];
vc.candidateid = [[NSString alloc] init];
vc.candidateid = [candidateid objectAtIndex:selectedIndexPath.row];
Though I was trying to pass data from VC to VC1, SIGABT happened on the last line.
Update:
I've got figured out how. Here is the script:
friendsDetailViewController* vc = [[friendsDetailViewController alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (friendsDetailViewController*)[[tbc customizableViewControllers] objectAtIndex:0];
Firstly, I have to attach Tab Bar Controller.
Secondly, retrieve each View Controller's pointer.
You can select by using objectIndex.
In childviewcontrollers of tab bar controllers you can easily pass data by using
[self.parentViewController.view setAccessibilityValue:#"your data"];
and can easily access this data in other child viewcontrollers of tabbar
or you can add an object in nsuserdefaults for some key and attach that key in parentviewcontroller.view ..
get that object by using objectforkey from nsuserdefaults in next viewcontroller
I had same problem.
I had NSString which i waned to be sent like this:
View Controller → Tab Bar Controller → VC1/VC2/VC3
Before anything else I created ViewController-s and TabBarController classes and connected them with storyboard.
This worked for me:
First lets send data from ViewController to TabBarController:
add segue to connect ViewController and TabBarController in storyboard and name it:
toMyTabController
add property u want to change in TabBarController:
#property (strong, nonatomic) NSString *name;
add this method somewhere in ViewController.m:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"toMyTabController"])
{
MyTabController *tabController = (MyTabController *)segue.destinationViewController;
tabController.name = #"SOME AWESOME NAME";
}
}
==================================================================================
Now lets send data from TabBarController to ViewController
Add property to every ViewController where you want to send info, and lets name it name (so creative)
add this to **ViewController1.h, ViewController2.h, ViewController3.h
#property (strong, nonatomic) NSString *name;
add this to ViewController1.m, ViewController2.m, ViewController3.m
#synthesize name;
go to your TabBarController.m and add this in ViewDidLoad method:
for (UIViewController* myController in self.viewControllers)
{
if([myController respondsToSelector:#selector(setName:)])
{
[myController performSelector:#selector(setName:) withObject:self.name];
}
}
Thats all,
Hope it helps. Good Luck

UITabBarController moreNavigationController as a grouped TableView?

I am using a UITabBarController that has more than 5 items, so it shows the more tab.
Is it possible to make this moreNavigationController be a grouped TableView (uitableviewstylegrouped)? Currently it defaults to a normal table view.
Try giving exactly 5, instead of giving more than 5 and let the 5th be the host of your grouped table view controller
The following code snippet does precisely that. It uses the instance of UITabBarController (here called controller) to get access to the navigation bar and tableview controller using the UITabBarController moreNavigationController property.
#define BACKGROUNDCOLOUR [UIColor colorWithRed:253.0/255.0 green:255.0/255.0 blue:240.0/255.0 alpha:1.0]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//... other init code
UINavigationBar *moreNavBar = controller.moreNavigationController.navigationBar;
moreNavBar.tintColor = [UIColor blackColor];
UITableView *moreTableView = (UITableView *)controller.moreNavigationController.topViewController.view;
[moreTableView initWithFrame:CGRectZero style:UITableViewStyleGrouped];
[moreTableView setBackgroundColor:BACKGROUNDCOLOUR];
[self.window addSubview:controller.view];
[self.window makeKeyAndVisible];
return YES;
}