我正在尝试创建一个简单的类作为我的注释MKMapView
.我正在获取我想要解析到这些注释对象的数据,并且认为使用字典初始化注释是一个好主意,并且在此模型类中而不是在a中进行所有解析UIViewController
.我似乎无法摆脱编译器错误,每当我尝试修复一个错误时,会出现另一个错误.
目前正在获取" self.coordinate
未在隐式生成的super.init
呼叫中初始化的属性" .无论我在该方法中进行调用,调用super.init()
仅产生不同的错误" self.coordinate
未在super.init
调用时初始化的属性" super.init()
.任何帮助将非常感激!这是我的代码现在的样子.
import Foundation
import MapKit
class Student: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var title: String
var subtitle: String
init(dictionary: Dictionary<String, AnyObject>) {
if let first = dictionary["firstName"] as? String {
if let last = dictionary["lastName"] as? String {
self.coordinate = CLLocationCoordinate2DMake(dictionary["latitude"] as! Double, dictionary["longitude"] as! Double)
self.title = first + " " + last
if let mediaURL = dictionary["mediaURL"] as? String …
Run Code Online (Sandbox Code Playgroud) 我想使用以下表达式
-(void)SwitchCondn{
int expression;
int match1=0;
int match2=1;
switch (expression)
{
case match1:
//statements
break;
case match2:
//statements
break;
default:
// statements
break;
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了
当我研究我发现
In order to work in Objective-C, you should define your constant either like this:
#define TXT_NAME 1
Or even better, like this:
enum {TXT_NAME = 1};
Run Code Online (Sandbox Code Playgroud)
我很久以来一直在使用这种方法.现在我的变量值将在运行时改变,所以我需要以其他方式定义,我不想使用if else所以有任何方式的声明变量其他方式
我接受了以下研究
为什么我不能在Objective-C中的switch-case语句中使用我的常量?[error = Expression不是整数常量表达式]
我似乎无法取代过时的sizeWithFont
与boundingRecWithSize
正确.我仔细检查了所有的答案,并熬夜试图解决这个问题.我真的需要一些比我聪明的人的帮助.这是我试图修改的代码.任何帮助,将不胜感激.
CGSize sizeForText = [faqItem.answer sizeWithFont:[UIFont boldSystemFontOfSize:14]
constrainedToSize:CGSizeMake(self.tblView.bounds.size.width - padding, MAXFLOAT)
lineBreakMode:NSLineBreakByWordWrapping];
[sectionInfo insertObject:[NSNumber numberWithFloat:roundf(sizeForText.height + 5)]
inRowHeightsAtIndex:0];
Run Code Online (Sandbox Code Playgroud) 如何自定义UIPickerView的高度超过250.我做了以下但无法达到给定的高度
-(void)pickerview:(id)sender
{
pickerView=[[UIPickerView alloc] initWithFrame:CGRectMake(0,200,320,400)];
pickerView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
pickerView.backgroundColor = [UIColor lightGrayColor];
[pickerView selectRow:1 inComponent:0 animated:YES];
[self.view addSubview:pickerView];
// [contentView addSubview:pickerView];
}
Run Code Online (Sandbox Code Playgroud) 我正在从字符串生成条形码,然后尝试将此图像保存到 iPhone 照片库。这是我的代码:
@IBOutlet weak var uuidLabel: UILabel!
@IBOutlet weak var barcodeDisplay: UIImageView!
@IBAction func generateBarcode(_ sender: Any) {
barcodeDisplay.image = generateBarcodeFromString(string: uuidLabel.text!)
UIImageWriteToSavedPhotosAlbum(barcodeDisplay.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}
@objc func image(_ image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: UnsafeRawPointer) {
if let error = error {
let ac = UIAlertController(title: "Save error", message: error.localizedDescription, preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
} else {
let ac = UIAlertController(title: "Saved!", message: "Your image has been saved to your photos.", preferredStyle: …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个UITableViewCell
包含一个UIImageView
和一些相关文本的自定义.我从互联网上获取图像,当图像加载时,我显示一个临时的UIImage
.
我正在使用一个单独的线程来获取UIImage
.一旦UIImage
下载,我在主线程上触发一个方法来设置图像UIImageView
(获取UIImageView
使用标签的实例)
但无论我做什么,图像都不会改变.单元格仍然显示较旧的图像(对应于不同的行 - 由于重复使用单元格)并且不反映新图像.日志语句显示正在调用设置图像的方法.
我甚至尝试将图像更改为静态图像,willDisplayCell:forRowAtIndexPath:
但即使这样,图像也不会改变.
编辑
我打过电话reloadData
的UITableView
改变后UIImage
,但UIImage
依然不改.
这是相关的代码段
的cellForRowAtIndexPath
image = [imagesArray valueForKey:[NSString stringWithFormat:@"%i",indexPath.row]];
if(image == nil){
//display temporary images. When scrolling stops, detach new thread to get images for rows visible
NSString *pth = [[NSBundle mainBundle] pathForResource:@"folder" ofType:@"png"];
image = [UIImage imageWithContentsOfFile:pth];
[imgView setImage:image];
}
else{
[imgView setImage:image];
}
Run Code Online (Sandbox Code Playgroud)
下载图像后在主线程上调用的方法
-(void)setImageInArray:(NSIndexPath *)indPath{
[filesTable reloadData]; …
Run Code Online (Sandbox Code Playgroud) 我的XIB中有一个名为"txt"的文本框和一个名为"next"的按钮.现在点击下一步按钮我想打印myArray的值.
NSArray *myArray
myArray = [NSArray arrayWithObjects:@"1",@"3",@"5",@"45",@"67",nil];
Run Code Online (Sandbox Code Playgroud)
谁能帮我这个.
我正在尝试更改所选内容UITableViewCell
,但这里发生了一些奇怪的事情.我放了两张图片.请看一下:
当我选择"早期"单元格时,它会变为蓝色.它转向'早期的等等' UIViewController
.然后当我点击"查找"时UIButton
,它会回到第一个视图.它工作,但细胞仍然选择蓝色!所以我写了一些代码如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if ([_currentMethod isEqual: @"searchIt"]) {
if (indexPath.row == 0) {
BookMark2ViewController* bookMark2 = [[BookMark2ViewController alloc] init];
UITableViewCell* cell = [self tableView:_tableView
cellForRowAtIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[self.navigationController pushViewController:bookMark2 animated:YES];
}else if (indexPath.row == 1) {
BookMarkViewController* bookMark1 = [[BookMarkViewController alloc] init];
[self.navigationController pushViewController:bookMark1 animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
代码中间的两行:
UITableViewCell* cell = [self tableView:_tableView
cellForRowAtIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Run Code Online (Sandbox Code Playgroud)
这两行没有用.有谁知道如何解决这一问题?
我正在努力UITableView
改变每个第二个单元格的背景颜色以帮助查看数据.
为此,我尝试创建一个名为"cellAlteration"的简单变量,在加载数据之前将其设置为0(因此第一个单元格应始终为白色)
var cellAlteration: Int = 0
Run Code Online (Sandbox Code Playgroud)
然后在我设置我的单元格的地方我执行以下操作:
// #BackgroundColor
if cellAlteration == 0 {
self.backgroundColor = UIColor.whiteColor()
cellAlteration = 1
} else {
self.backgroundColor = UIColor.formulaWhiteColor()
cellAlteration = 0
}
Run Code Online (Sandbox Code Playgroud)
(我知道这应该改为BOOL数据类型而不是Int,但这似乎与我的问题无关)
这是结果的图像:
你可以看到它没有正确交替.
当我一直试图测试它时,它看起来像是第一次正确UITableView
加载的单元格(只加载并显示你可以看到的单元格) - 着色的问题似乎不会发生,直到我向下滚动的UITableView
具有加载和显示新的细胞.
因为我的简单变量检查方法不起作用,在Swift中进行单元格交替的正确方法是什么?
任何帮助将不胜感激 :)!
宽高比"Scale To Fill"和"Aspect Fit"使图像拉伸到整个UIImageView大小.我如何使用看点填写"来handell的UIImageView内的UITableViewCell.UIImageView的内部的UITableViewCell在运行了屏幕的纵横填.我想使图像采取的是原始大小而不是伸展,但我想阻止它形成重叠了它的下部细胞.如果它低于下部细胞则更好.
第一个缩放以填充第二个方面填充
我用以下来选择图像模式
我的代码
Cell.m
- (void)awakeFromNib {
_img.clipsToBounds = YES;
_img.contentMode = UIViewContentModeScaleAspectFill;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
Run Code Online (Sandbox Code Playgroud)
VCUIViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
static NSString *CellIdentifier = @"NoticiasDetailImageCell";
NoticiasDetailImageCell *cell = (NoticiasDetailImageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; …
Run Code Online (Sandbox Code Playgroud) 我想创建如下所示的以下评级视图.怎么可能这样做
我有3个条件.我有顶部和下面的标签是星星,最后有TextField.好,惊人,恐怖根据星数设定.当有一星即可怕的情况时,我们必须提供四个按钮订单问题,时间,友好性,清洁度. UITextField
并在它下方转移
我已经实现了以下代码
#pragma mark - Btn Action on start click
- (IBAction)Btn_FirstHorrific:(id)sender {
[self ReviewHorrific];
[self NumOfStarWorstCase];
str_deliveryBoyRating=@"1";
str_customerComment=@"Horrific";
}
- (IBAction)Btn_SecondNah:(id)sender {
[self ReviewSecondNah];
[self NumOfStarOthercase];
str_deliveryBoyRating=@"2";
str_customerComment=@"nah!";
}
- (IBAction)Btn_ThirdItsOk:(id)sender {
[self ReviewItsOk];
[self NumOfStarOthercase];
str_deliveryBoyRating=@"3";
str_customerComment=@"Its ok";
}
- (IBAction)Btn_FourthGood:(id)sender {
[self ReviewGood];
[self NumOfStarOthercase];
str_deliveryBoyRating=@"4";
str_customerComment=@"good";
}
- (IBAction)Btn_FifthAmazing:(id)sender {
[self ReviewAmazing];
[self NumOfStarOthercase];
str_deliveryBoyRating=@"5";
str_customerComment=@"Amazing";
}
#pragma mark - Change star colour in Number of star changes
- (void)ReviewHorrific{
Btn_FirstHorrific.tintColor = UIColorFromRGB(0xff8133); …
Run Code Online (Sandbox Code Playgroud) 我参考了以下如何更改OFF状态的UISwitch默认颜色?
我有以下代码
- (void)viewDidLoad {
[super viewDidLoad];
self.termSwitch.layer.cornerRadius = 16.0;
[self SwitchStatus];
}
- (IBAction)SwitchStatusChange:(id)sender {
[self SwitchStatus];
}
- (void)SwitchStatus {
if ( self.termSwitch.on) {
[ self.termSwitch setThumbTintColor:[UIColor whiteColor]];
[ self.termSwitch setBackgroundColor:[UIColor clearColor]];
[ self.termSwitch setOnTintColor:[UIColor clearColor]];
}else{
[ self.termSwitch setTintColor:[UIColor clearColor]];
[ self.termSwitch setThumbTintColor:[UIColor whiteColor]];
[ self.termSwitch setBackgroundColor:[UIColor colorWithRed:0.384f green:0.859f blue:0.427f alpha:1.00f]];
}
}
Run Code Online (Sandbox Code Playgroud)
我无法为交换机放置白色边框,默认情况下交换机不平滑
我检查了以下链接,但它对我不起作用
ios ×9
objective-c ×6
uitableview ×4
swift ×3
iphone ×2
xcode ×2
aspect-ratio ×1
ciimage ×1
cocoa-touch ×1
deprecated ×1
ios7 ×1
ios8 ×1
qr-code ×1
rating ×1
sizewithfont ×1
tintcolor ×1
uibutton ×1
uiimage ×1
uiimageview ×1
uipickerview ×1
uiswitch ×1