I'm experiencing this weird behaviour once I initiate an application root controller with a UINavigationController
On first launch, there is an empty space between the navigationbar and first viewcontroller controller.
but the full content is displayed after I swtiched to another view and back to the first one.
Is something wrong with this?
tab_bar_controller = RootViewController.alloc.initWithNibName(nil, bundle:nil)
#window.rootViewController = UINavigationController.alloc.initWithRootViewController(tab_bar_controller)
Thanks for your help.
It is not considered "proper" to put a UITabBarController inside a UINavigationController:
UINavigationController#initWithRootViewController ... rootViewController:
The view controller that resides at the bottom of the navigation stack.
This object cannot be an instance of the UITabBarController class.
The opposite - a UINavigationController as one of the UITabBarController child view controllers - is allowed.
nav_controller = RootViewController.alloc.initWithNibName(nil, bundle:nil)
#window.rootViewController = UITabBarController.alloc.init
#window.rootViewController.viewControllers = [nav_controller]
Even if you did get this figured out, your app would ultimately be rejected.
Try placing the content in the viewWillAppear callback.
Related
So, I have few steps, last one contains EnvironmentObject and ObservedObject. The issue is, when I try to modify EnvironmentObject (lane 68) it re-creates ObservedObject.
Can any one explain me why this happens? Any solution to keep my ObservedObject with original state?
As far as I know it possible to change ObservedObject to StateObject, but I am using iOS 13+ so... I need other solution.
Line 47 - body is reevaluated so new instance of ObservedStuff is created, so make it as property and pass it in, like
struct TestView_A: View {
...
private let model = ObservedStuff()
var body: some View {
NavigationLink(destination: TestView_B(viewModel: self.model) ...
}
}
On a table row click I reference a cell to present a view controller (to select from a list of images)
def open_selector
view_b = ImagesController.new #using rmq hence .new
##cell.superview.superview.controller.presentViewController view_b, animated:true, completion:nil
end
Inside the images controller - I dismiss when finished selecting - but how do I let cell know it was closed?
def collectionView(view, didSelectItemAtIndexPath: index_path)
self.dismissViewControllerAnimated(true, completion: lambda{})
end
I would suggest providing your UICollectionViewController a delegate so it can call back itself. So:
class MyCollectionViewController < UICollectionViewController
attr_writer :parent_controller
# ...
def collectionView(view, didSelectItemAtIndexPath: index_path)
self.dismissViewControllerAnimated(true,
completion: lambda{
#parent_controller.collection_did_close(self)
})
end
Assuming, you have a method called collection_did_close in the parent controller, it will be called with a reference to the collection view controller. Using that you can grab whatever information you need out of there before it gets garbage collected.
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.
I am trying to set TextView width dynamically, Using setWidth(width) method.
txtviewOne.setWidth(10);
txtviewTwo.setWidth(10);
But not success.
Please help me How can I set width of textview dynamically.
TextView tv;
----------------------
tv=new TextView(this); // or tv=new TextView(R.id.textview1);
LinearLayout.LayoutParams Params1 = new LinearLayout.LayoutParams(15,50);
tv.setLayoutParams(Params1);
I call new TableRow(), because textView's parent is TableRow. If your parent's view is LinearLayout, replace it by new LinearLayout.LayoutParams.
textView.setLayoutParams(
new TableRow.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.MATCH_PARENT));
I have experienced something similar in situations where there is a ScrollView in the parents hierarchy. No matter how I would modify layout inside it, my commands were ignored. If this is the case, try calling RequestLayout on the ScrollView or remove and re-add the child view of the ScrollView.
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.