I'm trying to implement a basic QuickDialog view and the placement of the elements works fine.
But when I select an element the view won't scroll it into view. I thought the library would do this by itself or am I missing something?
Here is my code:
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
QRootElement *root = [[QRootElement alloc] init];
root.title = #"";
root.grouped = YES;
self.root = root;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
QSection *driverSection = [[QSection alloc] initWithTitle:#"xxx"];
QEntryElement *lblDriverSsn = [[QEntryElement alloc] initWithTitle:#"xxx" Value:#""];
lblDriverSsn.key = #"driverSsn";
QSection *vehicleSection = [[QSection alloc] initWithTitle:#"xxx"];
NSArray *component1 = #[#"xxx", #"xxx"];
QPickerElement *EventDescriptionPicker = [[QPickerElement alloc] initWithTitle:#"xxx" items:#[component1] value:#""];
EventDescriptionPicker.key = #"eventDescription";
NSMutableArray *speedValues = [[NSMutableArray alloc]init];
for (int i = 0; i <= 201; i+=5)
{
[speedValues addObject:[NSString stringWithFormat:#"%d%#", i,#" km/h"]];
}
QPickerElement *vehicleSpeed = [[QPickerElement alloc] initWithTitle:#"xxx" items:#[speedValues] value:#""];
self.damageReported = [[QBooleanElement alloc] initWithTitle:#"xxx" BoolValue:NO];
self.damageReported.onImage = [UIImage imageNamed:#"imgOn"];
self.damageReported.offImage = [UIImage imageNamed:#"imgOff"];
self.damageReported.controllerAction = #"showReportNumber:";
QEntryElement *lblReportNumber = [[QEntryElement alloc] initWithTitle:#"xxx" Value:#""];
lblDriverSsn.key = #"reportNumber";
//Sections
[driverSection addElement:lblDriverSsn];
[self.root addSection:driverSection];
[vehicleSection addElement:EventDescriptionPicker];
[vehicleSection addElement:vehicleSpeed];
[vehicleSection addElement:self.damageReported];
[vehicleSection addElement:lblReportNumber];
[self.root addSection:vehicleSection];
}
Am I missing something here?
Thanks in advance
On your initWithCoder: , set the following:
self.resizeWhenKeyboardPresented =YES;
This causes the view controller to listen for keyboard notifications , and adjust the inset accordingly.
Related
I am trying to add Carousel on the View as follows. As I testing it, nothing happens, it does not even hit any of carousel delegate method.
ViewController.h
#property (nonatomic, strong) iCarousel *carousel;
ViewController.m
carousel = [[iCarousel alloc] initWithFrame:CGRectMake(25, 50, self.view.frame.size.width-50, self.view.frame.size.height-75)];
[self.view addSubview:carousel];
carousel.delegate = self;
carousel.dataSource = self;
self.carousel.type = iCarouselTypeCoverFlow2;
self.items = [NSMutableArray array];
for (int i = 0; i < 100; i++)
{
[carouselItems addObject:#(i)];
}
[carousel reloadData];
Replace your code with this
self.carousel = [[iCarousel alloc] initWithFrame:CGRectMake(25, 50, self.view.frame.size.width-50, self.view.frame.size.height-75)];
self.carousel.delegate = self;
self.carousel.dataSource = self;
self.carousel.type = iCarouselTypeCoverFlow2;
[self.view addSubview:self.carousel];
self.items = [NSMutableArray array];
for (int i = 0; i < 100; i++)
{
[carouselItems addObject:#(i)];
}
[self.carousel reloadData];
Does anyone know why is appearing white part? My View is already gray, but gets two white pieces
whites: Arrow and final Popover!
[UPDATE]
this is the code that calls the popover and makes the arrow points to the button that was clicked!
- (void) buttonFilter {
if (viewFilter == #"Artistas") {
content = [self.storyboard instantiateViewControllerWithIdentifier:#"TipoArtistaViewController"]; // MUDAR PARA O NOVO FILTRO DE ARTISTAS
} else if (viewFilter == #"Músicas") {
content = [self.storyboard instantiateViewControllerWithIdentifier:#"CategoriaViewController"];
}
[self callFilter:btnFilter Filter:content];
}
- (void)callFilter:(id)sender Filter:(UIViewController *) content{
self.currentPop = popoverController;
popoverController = [[WYPopoverController alloc] initWithContentViewController:content];
UIButton * bt = (UIButton * )sender;
UIView *view = [bt valueForKey:#"view"];
popoverController.popoverContentSize = CGSizeMake(320, 180);
popoverController.delegate = self;
[popoverController presentPopoverFromRect:view.bounds inView:view permittedArrowDirections:WYPopoverArrowDirectionAny animated:YES];
}
the next is where to mount the session:
//extend and collpase
- (void)setupViewController {
categoriaBD = [categoriaDAO selectCategoria];
self.data = [[NSMutableArray alloc] init];
for (int i = 0; i < [categoriaBD count]; i++)
{
NSMutableDictionary * teste = [categoriaBD objectForKey:[NSString stringWithFormat:#"%i", i]];
ID = [[teste objectForKey:#"1"] integerValue];
subcategoriaBD = [categoriaDAO selectSubCategoriaByCategoriaID:ID];
NSMutableArray* section = [[NSMutableArray alloc] init];
for (int j = 0; j < [subcategoriaBD count]; j++)
{
NSMutableDictionary * subCat = [subcategoriaBD objectForKey:[NSString stringWithFormat:#"%i", j]];
[section addObject:[NSString stringWithFormat:[subCat objectForKey:#"1"]]];
}
[self.data addObject:section];
}
self.headers = [[NSMutableArray alloc] init];
for (int i = 0; i < [categoriaBD count]; i++)
{
NSString *inStr = [NSString stringWithFormat: #"%i", (int)i];
nomeCategoria = [categoriaBD objectForKey:inStr];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 310, 40)];
[label setText:[nomeCategoria objectForKey:#"2"]];
UIView* header = [[UIView alloc] init];
[header setBackgroundColor:[UIColor colorWithRed:(226/255.0) green:(226/255.0) blue:(226/255.0) alpha:1]];
[header addSubview:label];
[self.headers addObject:header];
}
}
You can to create a custom UIPopoverBackgroundView subclass that sets the properties of the arrow you want.
popoverController.popoverBackgroundViewClass = [MyPopoverBackgroundView class];
I have a template quiz application that has been on the app store in various guises for a while now, in general it receives good reviews and had no bug reports.
Recently I've had two bug reports, people using iPads with iOS 8.1.2 or 8.1.3, saying that now and again the UITextView that I use to show the questions is blank.
I've not been able to replicate this bug, but I would be grateful if someone could shed some light on it.
The objects questions and userAnswer are not nil so it is definitely a UITextView issue.
The Controller is here:
#interface ReviewController ()
#property (strong, nonatomic) IBOutlet UITextView *output;
#end
#implementation ReviewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setReviewText];
// Do any additional setup after loading the view.
}
-(void)setReviewText{
NSArray* questions = [[NSArray alloc] init];
questions = [_manager getAllQuestions];
NSMutableArray* userAnswer = [[NSMutableArray alloc] init];
userAnswer = [self answersAttributed];
if(questions == nil)
_output.text = #"Questions Error";
if (userAnswer == nil)
{
_output.text = #"Error";
}
NSMutableAttributedString *mutableAttString = [[NSMutableAttributedString alloc] init];
int i = 0;
NSAttributedString *linebreak =[[NSAttributedString alloc] initWithString:#"\n"];
for (Question* q in questions)
{
if (i == [userAnswer count])
break;
NSAttributedString *qtext =[[NSAttributedString alloc] initWithString:q.questionText];
NSAttributedString *ctext =[[NSAttributedString alloc] initWithString:#"Correct Answer:\n"];
NSAttributedString *atext =[[NSAttributedString alloc] initWithString:q.answerText];
NSAttributedString *ytext =[[NSAttributedString alloc] initWithString:#"Your Answer:\n"];
NSAttributedString *utext =[[NSAttributedString alloc] initWithAttributedString:userAnswer[i]];
[mutableAttString appendAttributedString:qtext];
[mutableAttString appendAttributedString:linebreak];
[mutableAttString appendAttributedString:ctext];
[mutableAttString appendAttributedString:atext];
[mutableAttString appendAttributedString:linebreak];
[mutableAttString appendAttributedString:ytext];
[mutableAttString appendAttributedString:utext];
[mutableAttString appendAttributedString:linebreak];
[mutableAttString appendAttributedString:linebreak];
i++;
}
NSAttributedString* outText = [[NSAttributedString alloc] init];
outText = [mutableAttString mutableCopy];
_output.attributedText = outText;
[_output setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]];
}
-(NSMutableArray*)answersAttributed
{
NSMutableArray* ansAtt = [[NSMutableArray alloc] init];
NSArray* questions = [[NSArray alloc] init];
questions = [_manager getAllQuestions];
NSArray* userAnswers = [[NSArray alloc] init];
userAnswers = [_manager getAllUserAnswers];
if ([questions count] != [userAnswers count])
{
return ansAtt;
}
int i = 0;
for (NSString* userAnswer in userAnswers )
{
if([[questions[i] answerText] isEqualToString:userAnswer] )
{
NSDictionary *attributes = #{NSBackgroundColorAttributeName:[UIColor greenColor]};
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:userAnswer attributes:attributes];
[ansAtt addObject:attrString];
}
else
{
NSDictionary *attributes = #{NSBackgroundColorAttributeName:[UIColor redColor]};
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:userAnswer attributes:attributes];
[ansAtt addObject:attrString];
}
i++;
}
return ansAtt;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:#"review2results"])
{
// Get reference to the destination view controller
ReviewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setManager:_manager];
}
}
With autolayout, if you don't have enough constraints to fully specify size and position, then sometimes you'll see and and sometimes you won't. The unspecified constraints can have random values, like 0 height or off screen position.
Check to make sure the constraints are fully specified.
In my case textview marked as Non-Editable and Non-Selectable in Storyboard have the same strange behavior on iOS 8.1 (no problems in iOS 9+).
- (void)viewDidLoad {
[super viewDidLoad];
textview.attributedText = [[NSAttributedString alloc] initWithString:#"non-nil"]];
value = textview.attributedText;
//^ value is nil !!!
}
Fixed with this:
- (void)viewDidLoad {
[super viewDidLoad];
textview.editable = YES;
textview.attributedText = [[NSAttributedString alloc] initWithString:#"non-nil"]];
textview.editable = NO;
value = textview.attributedText;
//^ value is #"non-nil" now !!!
}
I'm working on a baseball game app that contains multiple Modal View Controllers. However, when I make the modal transition from "BasicGameSetupViewController" to "BasicViewController", the transition happens (because I have NSLog statements within my ViewDidLoad method in the BasicViewController), but the actual view does not update. Here is the method where I transition to the BasicViewController (this code is in BasicGameSetupViewController):
- (IBAction)pressedBeginPlay:(id)sender {
numOfInnings = [selectInnings selectedSegmentIndex];
numOfInnings = numOfInnings + 1;
row = [teamSelector selectedRowInComponent:0];
visitor = [teams objectAtIndex:row];
row = [teamSelector selectedRowInComponent:1];
home = [teams objectAtIndex:row];
NSLog(#"%#", visitor);
NSLog(#"%#", home);
if([awaySelect selectedSegmentIndex] == 0)
{
awayPlayer = #"Human";
}
else
{
awayPlayer = #"CPU";
}
if([homeSelect selectedSegmentIndex] == 0)
{
homePlayer = #"Human";
}
else
{
homePlayer = #"CPU";
}
[self performSegueWithIdentifier:#"startBeginnerToBasic" sender:self];
}
(This block also has a "prepareForSegue" method)
And here is the viewDidLoad method in BasicViewController:
- (void)viewDidLoad{
NSLog(#"Made it to basic View controller");
homeLineup = [[NSMutableArray alloc] initWithCapacity:9];
visitorLineup = [[NSMutableArray alloc] initWithCapacity:9];
batter = [[NSMutableArray alloc] initWithCapacity:22];
homePitcher = [[NSMutableArray alloc] initWithCapacity:22];
awayPitcher = [[NSMutableArray alloc] initWithCapacity:22];
pitcher = [[NSMutableArray alloc] initWithCapacity:22];
homeAlreadyPitched = [[NSMutableArray alloc]initWithCapacity:5];
awayAlreadyPitched = [[NSMutableArray alloc] initWithCapacity:5];
NSLog(#"arrays initialized");
[super viewDidLoad];
[self setUpTeams];
[self checkForComputer];
[self newBatter];
[self atBat];
// Do any additional setup after loading the view.
}
I'm completely stumped as to why my view isn't showing. The NSLog statements that are in the ViewDidLoad code block above show up, but the I can't get the view to show. Does anyone have any ideas?
Thank you in advance for your help!
When my view is trying to load, the applications crashes and i get this stack:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
This is my code, i don't really know where to look when this crash is occurred:
#import "Itineraire.h"
#import "SBMapView.h"
#import "SBRouteAnnotation.h"
#import "City.h"
#import "UICGRoutes.h"
#import "SBCheckPointViewController.h"
//#import "SBRouteDetailView.h"
#interface Itineraire(Private)
-(void)customInitialization;
#end
#implementation Itineraire(Private)
-(void)customInitialization
{
// do the initialization of class variables here..
mDirections = [UICGDirections sharedDirections];
mDirections.delegate = self;
}
#end
#implementation Itineraire
#synthesize map = mMap;
#synthesize startPoint = mStartPoint;
#synthesize endPoint = mEndPoint;
#synthesize loadBtn = mLoadBtn;
#synthesize annotationArray = mAnnotationArray;
#synthesize travelMode = mTravelMode;
#synthesize destination;
#synthesize routes;
#synthesize mAnnotations;
#synthesize mRouteArray;
#synthesize mRouteDetail;
//Invoked when the class is instantiated in XIB
-(id)initWithCoder:(NSCoder*)aDecoder
{
self = [super initWithCoder:aDecoder];
if( self)
{
[self customInitialization];
}
return self;
}
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
[self customInitialization];
}
return self;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Google Maps";
self.map = [[SBMapView alloc] initWithFrame:CGRectMake(0, 49, self.view.frame.size.width, self.view.frame.size.height)];
//self.map = [[SBMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 381)];
[self.view addSubview:mMap];
self.view.backgroundColor = [UIColor blackColor];
self.annotationArray = [[NSMutableArray alloc]init];
self.routes = [[UICGRoutes alloc]init];
if (mDirections.isInitialized) {
[self updateRoute];
}
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
}
- (void)viewWillDisappear:(BOOL)animated;
{
[super viewWillDisappear:YES];
}
#pragma mark -
#pragma mark Instance Methods
- (void)updateRoute
{ /*
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
UICGDirectionsOptions *options = [[[UICGDirectionsOptions alloc] init] autorelease];
options.travelMode = mTravelMode;
City *mFirstCity = [[[City alloc]init] autorelease];
mFirstCity.mCityName = #"Paris";//mStartPoint;
//[mDirections loadWithStartPoint:mFirstCity.mCityName endPoint:destination options:options];
//added
NSMutableArray * DestinationCityArray = [[NSMutableArray alloc]init];
[DestinationCityArray addObject:#"Berlin"];
[mDirections loadWithStartPoint:mFirstCity.mCityName endPoint:destination options:options];
*/
//
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
UICGDirectionsOptions *options = [[UICGDirectionsOptions alloc] init] ;
options.travelMode = mTravelMode;
City *mFirstCity = [[City alloc]init];
mFirstCity.mCityName = #"Amsterdam";//mStartPoint;
NSMutableArray *dest=[[NSMutableArray alloc]init];
[dest addObject:#"Berlin"];
[mDirections loadWithStartPoint:mFirstCity.mCityName endPoint:dest options:options];
}
-(void)loadRouteAnnotations
{
self.mRouteArray = [mDirections routeArray];
NSLog(#"mRouteArray %#",mRouteArray);
self.mAnnotations = [[NSMutableArray alloc]init];
for (int idx = 0; idx < [mRouteArray count]; idx++) {
NSArray *_routeWayPoints1 = [[mRouteArray objectAtIndex:idx] wayPoints];
NSArray *mPlacetitles = [[mRouteArray objectAtIndex:idx] mPlaceTitle];
self.annotationArray = [NSMutableArray arrayWithCapacity:[_routeWayPoints1 count]-2];
mLoadBtn.title = #"OFF";
mLoadBtn.target = self;
mLoadBtn.action = #selector(removeRouteAnnotations);
for(int idx = 0; idx < [_routeWayPoints1 count]-1; idx++)
{
mBetweenAnnotation = [[SBRouteAnnotation alloc] initWithCoordinate:[[_routeWayPoints1 objectAtIndex:idx]coordinate]
title:[mPlacetitles objectAtIndex:idx]
annotationType:SBRouteAnnotationTypeWayPoint];
[self.annotationArray addObject:mBetweenAnnotation];
}
[mAnnotations addObject:mAnnotationArray];
[self.map.mapView addAnnotations:[mAnnotations objectAtIndex:idx]];
NSLog(#"map %#",mMap);
}
}
-(void)showCheckpoints
{
SBCheckPointViewController *_Controller = [[SBCheckPointViewController alloc]initWithNibName:#"SBCheckPoints" bundle:nil];
[self.navigationController pushViewController:_Controller animated:YES];
NSMutableArray *arr = [[mDirections checkPoint] mPlaceTitle];
_Controller.mCheckPoints = arr ;
}
//
-(void)removeRouteAnnotations
{
NSMutableArray *mTempAnnotation;// = [mAnnotations retain];
for (int idx = 0; idx < [mTempAnnotation count]; idx++) {
[mMap.mapView removeAnnotations:[mTempAnnotation objectAtIndex:idx] ];
}
mLoadBtn.title = #"ON";
mLoadBtn.target = self;
mLoadBtn.action = #selector(loadRouteAnnotations);
}
#pragma mark <UICGDirectionsDelegate> Methods
- (void)directionsDidFinishInitialize:(UICGDirections *)directions {
[self updateRoute];
}
- (void)directions:(UICGDirections *)directions didFailInitializeWithError:(NSError *)error {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Map Directions" message:[error localizedFailureReason] delegate:nil cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alertView show];
}
- (void)directionsDidUpdateDirections:(UICGDirections *)indirections {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
UICGPolyline *polyline = [indirections polyline];
NSArray *routePoints = [polyline routePoints];
[mMap loadRoutes:routePoints]; // Loads route by getting the array of all coordinates in the route.
UIToolbar *tools = [[UIToolbar alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)]; // 44.01 shifts it up 1px for some reason
tools.clearsContextBeforeDrawing = NO;
tools.clipsToBounds = NO;
tools.tintColor = [UIColor colorWithWhite:0.305f alpha:0.0f]; // closest I could get by eye to black, translucent style.
// anyone know how to get it perfect?
tools.barStyle = -1; // clear background
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];
// Create a standard Load button.
self.loadBtn = [[UIBarButtonItem alloc]initWithTitle:#"ON"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(loadRouteAnnotations)];
[buttons addObject:mLoadBtn];
// Add Go button.
UIBarButtonItem *mGoBtn = [[UIBarButtonItem alloc] initWithTitle:#"Go"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(showCheckpoints)];
[buttons addObject:mGoBtn];
// Add buttons to toolbar and toolbar to nav bar.
[tools setItems:buttons animated:NO];
UIBarButtonItem *twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
self.navigationItem.rightBarButtonItem = twoButtons;
//Add annotations of different colors based on initial and final places.
SBRouteAnnotation *startAnnotation = [[SBRouteAnnotation alloc] initWithCoordinate:[[routePoints objectAtIndex:0] coordinate]
title:mStartPoint
annotationType:SBRouteAnnotationTypeStart];
SBRouteAnnotation *endAnnotation = [[SBRouteAnnotation alloc] initWithCoordinate:[[routePoints lastObject] coordinate]
title:mEndPoint
annotationType:SBRouteAnnotationTypeEnd];
[mMap.mapView addAnnotations:[NSArray arrayWithObjects:startAnnotation, endAnnotation,nil]];
}
- (void)directions:(UICGDirections *)directions didFailWithMessage:(NSString *)message {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Map Directions" message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alertView show];
}
#pragma mark -
#end
I tried to put my code on a new project (empty application) and it worked fine, i didn't understand that error and its possible causes.
EDIT:
I tried to track the problem by elimination,and my code worked fine when i remove this method:
//Invoked when the class is instantiated in XIB
-(id)initWithCoder:(NSCoder*)aDecoder
{
self = [super initWithCoder:aDecoder];
if( self)
{
[self customInitialization];
}
return self;
}
However, when i run, my app doesn't display me the route between the two points (The purpose of the app). So this method seems important for the whole class because without it, i couldn't get the route and in the other side when it's there, the app crashes. How should i deal with this contradiction?
#Vince is putting you on the right track. Since the problem is in an NSURL method being called by a framework (Google Maps in this case) you need to debug what you are passing to the framework. You have the source for the framework also right? You can set breakpoints in loadWithStartPoint:endPoint:options:] to see what's going on.
One thing I did notice is you are passing an NSMutableArray as the endPoint param when I believe it expects an NSString.