#import "MYViewController.h"
#import "DataSyncHandler.h"
#import "ParentTableViewCell.h"
#import "Ayaah.h"
static NSString *ParentCellIdentifier = @"ParentTableViewCell";
@interface MYViewController ()
{
double pinchscale;
UIPinchGestureRecognizer *twoFingerPinch;
CGPoint buttonPosition;
NSIndexPath *iPath;
DBManager *bmanager;
CGPoint p;
UIFont *df;
UIFont *df1;
NSMutableArray *header;
NSUserDefaults *defaults;
CGAffineTransform cg;
}
@end
@implementation MYViewController
@synthesize dataSource;// nsmutable array which have filled from sqlite databasedata
@synthesize ptc;// customcell
- (void)viewDidLoad
{
[super viewDidLoad];
self.dataSource=[[NSMutableArray alloc]init];
cg=_tableView.transform;
self.tableView.estimatedRowHeight = 80.0;
_tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.delegate=self;
self.tableView.dataSource=self;
UIPinchGestureRecognizer * recognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)];
recognizer.delegate = self;
[_tableView addGestureRecognizer:recognizer];
[self fetchmoreAyah];
}
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
header=[[NSMutableArray alloc]init];
for (int i = 0; i<[self.dataSource count]; i++) {
[header addObject:[@(i) stringValue]];
}
[self fetchmoreAyah];
[self.tableView reloadData];
}
- (void)fetchmoreAyah {
defaults=[NSUserDefaults standardUserDefaults];
//custom font name and size set by user in settings and creating new font according to users desire
df=[UIFont fontWithName:[defaults objectForKey:@"FontStyle"] size:(CGFloat)[[defaults objectForKey:@"Font"] floatValue]];
df1=[UIFont systemFontOfSize:(CGFloat)[[defaults objectForKey:@"Font"] floatValue]];
self.dataSource=[[DataSyncHandler defaultHandler] fetchCompleteSurahForSelectedSurahID:self.surahId andUrduTranslatorRef:[defaults objectForKey:@"Language"] andEngTranslatorRef:[defaults objectForKey:@"Translator" ]];
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ParentTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:ParentCellIdentifier];
if (!cell) {
cell = [[ParentTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:ParentCellIdentifier];
}
Ayaah * ayaahObj = [self.dataSource objectAtIndex:indexPath.row];
[self setSubtitleForCell:cell item:ayaahObj];
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"gmii.jpg"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
[cell setNeedsLayout];
[cell layoutIfNeeded];
return cell;
}
- (void)setSubtitleForCell:(ParentTableViewCell *)cell item:(Ayaah *)item {
cell.ArbiLabel.font =df;
cell.EnglishLabel.font = df1;
cell.urdulabl.font=df1;
[cell.idlbl setText:item.ayaahID];
NSDecimalNumber *someNumber = [NSDecimalNumber decimalNumberWithString:item.ayaahID];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSLocale *arLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"ar"];
[formatter setLocale:arLocale];
NSString *str=[NSString stringWithFormat:@"%@﴿%@﴾",item.ayaahText,[formatter stringFromNumber:someNumber]];
[cell.ArbiLabel setText:str];
if(![[defaults objectForKey:@"Language" ] isEqualToString:@"None"])
{
[cell.urdulabl setText:item.urduTranslationText];
cell.urdulabl.textAlignment=NSTextAlignmentRight;
if (![[defaults objectForKey:@"Translator" ] isEqualToString:@"None"])
{
[cell.EnglishLabel setText:item.englishTranslationText];
}
else
{
[cell.EnglishLabel setText:@""];
}
}
else
{
if (![[defaults objectForKey:@"Translator" ] isEqualToString:@"None"])
{
[cell.EnglishLabel setText:item.englishTranslationText];
cell.EnglishLabel.textAlignment=NSTextAlignmentLeft;
[cell.urdulabl setText:@""];
}
else
{
[cell.EnglishLabel setText:@""];
[cell.urdulabl setText:@""];
}
}
}
- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer
{
if(recognizer.state==UIGestureRecognizerStateEnded)
{
_tableView.transform=cg;
[self.tableView reloadData];
}
else
{
pinchscale=0.0;
pinchscale = recognizer.scale;
// pinchscale = round(pinchscale * 1000) / 1000.0;
CGFloat fontSize = df.pointSize;
if (pinchscale < 1) {
if(fontSize>14)
{
_tableView.transform=CGAffineTransformMakeScale(pinchscale, pinchscale);
pinchscale=.55;
df=[UIFont fontWithName:[defaults objectForKey:@"FontStyle"] size:(CGFloat)[[defaults objectForKey:@"Font"] floatValue] - pinchscale];
df1=[UIFont systemFontOfSize:(CGFloat)[[defaults objectForKey:@"Font"] floatValue] - pinchscale];
CGFloat FontSize = df.pointSize;
[defaults setObject:[NSString stringWithFormat:@"%.0f", FontSize] forKey:@"Font"];
}
}
else if(pinchscale>1){
if(fontSize<60&&fontSize>=13)
{
_tableView.transform=CGAffineTransformMakeScale(pinchscale, pinchscale);
pinchscale=pinchscale/3;
df=[UIFont fontWithName:[defaults objectForKey:@"FontStyle"] size:(CGFloat)[[defaults objectForKey:@"Font"] floatValue] + pinchscale];
df1=[UIFont systemFontOfSize:(CGFloat)[[defaults objectForKey:@"Font"] floatValue] + pinchscale];
CGFloat FontSize = df.pointSize;
[defaults setObject:[NSString stringWithFormat:@"%.0f", FontSize] forKey:@"Font"];
}
}
// [fontSize r];
}
//
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return header;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
for (int i = 0; i< index; i++) {
Ayaah * ayaahObj = [dataSource objectAtIndex:i];
NSString *letterString =ayaahObj.ayaahID ;
if ([letterString isEqualToString:title]) {
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
break;
}
}
return -1;
}
@end
**当字体大小为15时它消耗100mb到200mb,当输入代码时,这里输入代码增加我的字体大小15到45或60然后我的应用程序崩溃和内存从200mb + 400 + +崩溃和消息显示应用程序崩溃由于内存管理。我正在使用有3个标签**的自定义单元格