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'm starting to get brave and am attempting to populate a JBChartView (specifically a line chart) into my application for statistics tracking. I've never worked with a graphing library before but I did my best to look into them and this one seemed very robust. Problem is I'm having trouble getting the plots to work correctly from test data.
When I run the code as follows below, I get [__NSCFConstantString objectAtIndex:] unrecognized selector sent to instance. The offending line is at verticalValueforHorizontalIndex but I can't figure out another way to produce any data. Does anyone have any experience with this or can anyone help me figure out why I'm getting so much trouble here?
Implementation File
#import "waterStatsViewController.h"
#import "JBLineChartView.h"
#import "JBChartView.h"
#import "JBBarChartView.h"
#import "JBChartHeaderView.h"
#import "JBLineChartFooterView.h"
typedef NS_ENUM(NSInteger, JBLineChartLine){
JBLineChartLineSolid,
JBLineChartLineDashed,
JBLineChartLineCount
};
#interface waterStatsViewController ()
- (void)initData;
#end
#implementation waterStatsViewController
- (id)init
{
self = [super init];
if (self)
{
[self initData];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
[self initData];
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
[self initData];
}
return self;
}
- (void) initData
{
// DEFINE ARRAYS
testArray1 = [[NSArray alloc] initWithObjects:#"1", #"2", #"3", #"4", #"5", #"6", #"7", #"8", #"9", #"10", nil];
testArray2 = [[NSArray alloc] initWithObjects:#"1", #"2", #"3", #"4", #"5", #"6", #"7", #"8", #"9", #"10", nil];
// CREATE MUTABLE ARRAY FOR LINES IN CHART
NSMutableArray *mutableLineCharts = [NSMutableArray array];
// AS LONG AS LINEINDEX IS LESS THEN THE LINE COUNT, INCREASE THE LINE COUNT AND EXECUTE CODE
for (int lineIndex = 0; lineIndex<JBLineChartLineCount; lineIndex++)
{
// CREATE MUTABLE ARRAY FOR DATA IN CHART
NSMutableArray *mutableChartData = [NSMutableArray array];
// AS LONG AS INT I IS LESS THEN THE COUNT OF OBJECTS IN TEST ARRAY 2; INCREASE COUNT AND EXECUTE CODE
for (int i = 0; i < testArray2.count; i++)
{
// ADD OBJECTS FROM TEST ARRAY 2 TO CHART DATA
[mutableChartData addObjectsFromArray:testArray2];
}
// TAKE OBJECTS FROM MUTABLE CHART DATA AND ADD THEM TO OHHHHHH FOR EACH ITEM YOU ADD ANOTHER LINE
[mutableLineCharts addObjectsFromArray:mutableChartData];
}
}
- (void)viewDidLoad
{
self.title = #"Water Quality";
_chartView = [[JBLineChartView alloc] init];
_chartView.delegate = self;
_chartView.dataSource = self;
_chartView.state = 0;
_chartView.backgroundColor = [UIColor blackColor];
_chartView.showsLineSelection = YES;
_chartView.showsVerticalSelection = YES;
_headerView = [[JBChartHeaderView alloc] initWithFrame:CGRectMake(0, 64, 320, 30)];
_chartView.frame = CGRectMake(0, 94, 320, 300);
_footerView = [[JBLineChartFooterView alloc] initWithFrame:CGRectMake(0, 404, 320, 30)];
_headerView.titleLabel.text = #"Alkalinity";
_headerView.titleLabel.textColor = [UIColor whiteColor];
_footerView.leftLabel.text = [testArray1 firstObject];
_footerView.rightLabel.text = [testArray1 lastObject];
_footerView.leftLabel.textColor = [UIColor whiteColor];
_footerView.rightLabel.textColor = [UIColor whiteColor];
_footerView.backgroundColor = [UIColor blackColor];
_footerView.sectionCount = [testArray1 count];
// THIS IS THE VIEW WHEN THE USER INTERACTS WITH THE CHART
/*
_informationView = [[JBChartInformationView alloc] initWithFrame:CGRectMake(0, 0, 40, 300)];
[_informationView setBackgroundColor:[UIColor grayColor]];*/
[_chartView setMinimumValue:1.0f];
[_chartView setMaximumValue:20.0f];
[self.view addSubview:_footerView];
[self.view addSubview:_headerView];
[self.view addSubview:_chartView];
// [self.view addSubview:_informationView];
[_chartView reloadData];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (BOOL)lineChartView:(JBLineChartView *)lineChartView showsDotsForLineAtLineIndex:(NSUInteger)lineIndex;
{
return YES;
}
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return 1;
}
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
return 1;
}
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
{
return [[[testArray2 objectAtIndex:lineIndex] objectAtIndex:horizontalIndex] floatValue];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
A few issues:
Don't store numeric values as strings in your test arrays.
Remove the mutableLineCharts code; this is leftover from the demo and not needed for your purposes.
I assume you want two lines? One dashed and one solid? If so, return JBLineChartLineCount instead of 1 for numberOfLinesInLineChartView.
Return the numeric value for testArray1 or testArray2 in verticalValueForHorizontalIndex.
Initializing Data
- (void) initData
{
testArray1 = #[#(1), #(2), #(3), #(4), #(5), #(6), #(7), #(8), #(9), #(10)];
testArray2 = #[#(11), #(12), #(13), #(14), #(15), #(16), #(17), #(18), #(19), #(20)];
}
Line Count
- (NSUInteger)numberOfLinesInLineChartView:(JBLineChartView *)lineChartView;
{
return JBLineChartLineCount;
}
Data Count
- (NSUInteger)lineChartView:(JBLineChartView *)lineChartView numberOfVerticalValuesAtLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
return [self.testArray1 count];
}
else
{
return [self.testArray2 count];
}
return 0;
}
Data Value
- (CGFloat)lineChartView:(JBLineChartView *)lineChartView verticalValueForHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex;
{
if (lineIndex == JBLineChartLineSolid)
{
NSNumber *value = (NSNumber *)[self.testArray1 objectAtIndex:horizontalIndex];
return [value floatValue];
}
else
{
NSNumber *value = (NSNumber *)[self.testArray2 objectAtIndex:horizontalIndex];
return [value floatValue];
}
return 0;
}
Hope this helps.
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.
[EDIT]
Ok I found the problem, I was just calling the bad connection request of my web service. So downloading a blog would erase the articles list content. Time for a break :p
#
I'm upgrading an old app which is a simple RSS reader with a list of articles and a list of blogs. Each of these is a UITableView with its own UITableViewController.
Both of them retrieve data from a JSON file on my server.
At the end of the JSON parsing I update the dataSources and then call the reloadData method on both tableviews. The problem is that the articles list is filled with the blogs and the blog list isn't filled at all.
If I don't call reloadData on the blog tableview, the article one is filled correctly and works well. As seen on an other post I've tried with the tableview.tag identifier but it doesn't work.
Note: I'm not using IB.
Here is the code for the BlogTableViewController:
#implementation BlogsTVC
#synthesize dataSourceForBlogs;
#synthesize blogRec;
- (id)initWithStyle:(UITableViewStyle)style
{
if ((self = [super initWithStyle:style])) {
self.title = #"Blogs";
self.tableView.tag = 2;
self.tableView.delegate = self;
dataSourceForBlogs = [[NSMutableArray alloc] init];
// Register to notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callback_blogs:) name:#"blogs" object:nil ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(connection_error:) name:#"connection_error" object:nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self refreshBlogs];
}
-(void)callback_blogs:(NSNotification *)notification
{
if([self.dataSourceForBlogs count] > 0)
{
NSInteger i, count = [self.dataSourceForBlogs count];
for(i=0; i < count; i++)
{
[[self.dataSourceForBlogs objectAtIndex:i] release];
}
[self.dataSourceForBlogs removeAllObjects];
}
//remplissage
NSArray *receivedDatas = [[notification userInfo] objectForKey:#"data"];
NSUInteger i, count = [receivedDatas count];
for(i=0; i<count; i++)
{
self.blogRec = [[BlogRecord alloc] init];
self.blogRec.blog_id_auteur = [[receivedDatas objectAtIndex:i] objectForKey:#"id"];
self.blogRec.blog_auteur = [[receivedDatas objectAtIndex:i]objectForKey:#"auteur"];
self.blogRec.blog_url = [[receivedDatas objectAtIndex:i]objectForKey:#"url"];
self.blogRec.blog_date = [[receivedDatas objectAtIndex:i] objectForKey:#"date"];
self.blogRec.blog_nb_pub = [[receivedDatas objectAtIndex:i] objectForKey:#"nb_publication"];
self.blogRec.blog_url_image = [[receivedDatas objectAtIndex:i] objectForKey:#"theme"];
[self.dataSourceForBlogs addObject:self.blogRec];
self.blogRec = nil;
}
[self.tableView reloadData];
}
Here is the code for the Articles:
#implementation ActualiteTVC
#synthesize dataSource;
#synthesize artRec;
#pragma mark -
#pragma mark Initialization
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if ((self = [super initWithStyle:style])) {
// Titles
self.title = #"Actualités";
self.tableView.tag = 1;
// Register to notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callback_general:) name:#"general" object:nil ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(connection_error:) name:#"connection_error" object:nil];
self.dataSource = [[NSMutableArray alloc] init];
}
return self;
}
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
[self refreshNews];
}
-(void)callback_general: (NSNotification *) notification
{
if ([self.dataSource count] > 0) {
NSUInteger i, count = [self.dataSource count];
for (i = 0; i < count; i++) {
[[self.dataSource objectAtIndex:i] release];
}
[self.dataSource removeAllObjects];
}
NSArray *receivedDatas = [[notification userInfo] objectForKey:#"data"];
NSUInteger i, count = [receivedDatas count];
for (i = 0; i < count; i++) {
self.artRec = [[ArticleRecord alloc] init];
self.artRec.art_id = [[receivedDatas objectAtIndex:i] objectForKey:#"id"];
self.artRec.art_auteur = [[receivedDatas objectAtIndex:i] objectForKey:#"auteur"];
self.artRec.art_categorie = [[receivedDatas objectAtIndex:i] objectForKey:#"categorie"];
self.artRec.art_date = [[receivedDatas objectAtIndex:i] objectForKey:#"date"];
//self.artRec.art_texte = [[receivedDatas objectAtIndex:i] objectForKey:#"texte"];
self.artRec.art_titre = [[receivedDatas objectAtIndex:i] objectForKey:#"titre"];
self.artRec.art_url_auteur = [[receivedDatas objectAtIndex:i] objectForKey:#"url_auteur"];
self.artRec.art_url = [[receivedDatas objectAtIndex:i] objectForKey:#"url"];
self.artRec.art_url_img = [[receivedDatas objectAtIndex:i] objectForKey:#"image"];
[self.dataSource addObject:self.artRec];
self.artRec = nil;
}
[self.tableView reloadData];
}
Finally here is how I add these TableViews in the TabBar:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 0
//articles
ActualiteTVC *actualiteTVC = [[ActualiteTVC alloc] init];
UINavigationController *actualiteNC = [[UINavigationController alloc] initWithRootViewController:actualiteTVC];
[actualiteTVC release];
actualiteNC.tabBarItem.title = #"Actualités";
actualiteNC.tabBarItem.image = [UIImage imageNamed:#"08-chat.png"];
[actualiteNC.navigationBar setBarStyle:UIBarStyleBlack];
//1
//blogs
BlogsTVC *blogsTVC = [[BlogsTVC alloc] init];
UINavigationController *blogsNC = [[UINavigationController alloc] initWithRootViewController:blogsTVC];
[blogsTVC release];
blogsNC.tabBarItem.title = #"Blogs";
blogsNC.tabBarItem.image = [UIImage imageNamed:#"balance.png"];
[blogsNC.navigationBar setBarStyle:UIBarStyleBlack];
// myTabBarController
myTabBarController = [[UITabBarController alloc] init];
[myTabBarController setViewControllers:[NSArray arrayWithObjects:actualiteNC, blogsNC, nil]];
[actualiteNC release];
[blogsNC release];
/*
//fullscreen
CGRect frame = [[UIScreen mainScreen] applicationFrame];
frame.origin.x = 0;
frame.origin.y = 25;
//[baseViewCtrl.view setFrame:frame];
[myTabBarController.view setFrame:frame];
*/
/*
// window
//[window addSubview:myTabBarController.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleRemoveLoading:) name:#"removeLoading" object:nil];
loading = [[LoadingVC alloc] init];
[window addSubview:loading.view];
*/
[window addSubview:baseViewCtrl.view];
[window makeKeyAndVisible];
return YES;
}
How would you change this method to allow images to be in via an array rather than colors? As I have mySQL database which passing in urls which are assigned as NSStrings in xcode which are stored in an array.
Idea being that each view has set background image from the mySQL database.
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor blueColor],
[UIColor greenColor],[UIColor yellowColor] , nil];
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.size = self.scrollView.frame.size;
self.scrollView.pagingEnabled = YES;
UIView *subview = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [colors objectAtIndex:i];
[self.scrollView addSubview:subview];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
}
I made a try with (introNames is class where id and names of images are held from the mySQL database. The imageArray was created in the above code class and nsstrings from introNames were assigned to it).
- (void)viewDidLoad
{
[super viewDidLoad];
for (int i = 0; i < imageArray.count; i++) {
introImages *snap = [imageArray objectAtIndex:i];
imageName2 = snap.imageName;
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.size = self.scrollView.frame.size;
self.scrollView.pagingEnabled = YES;
UIView *subview = [[UIView alloc] initWithFrame:frame];
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName2]];
[subview addSubview:backgroundView];
[self.scrollView addSubview:subview];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * imageArray.count, self.scrollView.frame.size.height);
}
This is the working data retrieval system.
-(void) retrieveData
{
NSURL *url = [NSURL URLWithString:getDataUrl];
NSData *data = [NSData dataWithContentsOfURL:url];
if (data) {
jsonConnection = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
imageArray = [[NSMutableArray alloc]init];
for (int i = 0; i < jsonConnection.count; i++)
{
NSString *pID = [[jsonConnection objectAtIndex:i] objectForKey:#"id"];
NSString *pName = [[jsonConnection objectAtIndex:i] objectForKey:#"ImagesURL"];
introImages *myImages = [[introImages alloc]initWithimageID:pID andimageName:pName];
[imageArray addObject:myImages];
}
}
else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:#"Something is wrong with your internet connection" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
Any ideas would be great :)
If you are not using iOS6+ in you app use this class PSTCollectionView
and if you are using iOS6 and above use UICollectionView Class Reference