我有我的阵列:
self.colorNames = [[NSArray alloc]
initWithObjects:@"Red", @"Green",
@"Blue", @"Indigo", @"Violet", nil];
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有我能找到的东西,但总会出现错误.我希望能够滑动以显示删除按钮,然后按删除按钮并删除该行.
完整代码(与表有关的所有内容):
// HEADER FILE
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *tableView;
NSMutableArray *colorNames;
}
@property (strong, nonatomic) NSArray *colorNames;
@end
// IMPLEMENTATION
#import "ViewController.h"
@implementation ViewController
@synthesize colorNames;
- (void)viewDidLoad {
[super viewDidLoad];
self.colorNames = [[NSMutableArray alloc]
initWithObjects:@"Red", @"Green",
@"Blue", @"Indigo", @"Violet", nil];
[super viewDidLoad];
//[tableView setEditing:YES animated:NO];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table …Run Code Online (Sandbox Code Playgroud) 我有一个UIButton,我已经创建了一个扩展,为不同的状态添加背景颜色.
我正在使用以下代码:
extension UIButton {
func setBackgroundColor(color: UIColor, forState: UIControlState) {
UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), color.CGColor)
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRect(x: 0, y: 0, width: 1, height: 1))
let colorImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.setBackgroundImage(colorImage, forState: forState)
}
}
// Set Button Title and background color for different states
self.donateButton.setBackgroundColor(UIColor.redColor(), forState: .Normal)
self.donateButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
self.donateButton.setBackgroundColor(UIColor.greenColor(), forState: .Highlighted)
self.donateButton.setTitleColor(UIColor.whiteColor(), forState: .Highlighted)
self.donateButton.setBackgroundColor(UIColor.greenColor(), forState: .Selected)
self.donateButton.setTitleColor(UIColor.whiteColor(), forState: .Selected)
Run Code Online (Sandbox Code Playgroud)
我的问题是它没有
UIButton为突出显示/选择状态选择适当的背景颜色和标题颜色.
我已经实现了自定义输入附件视图,它工作正常,直到iOS 10.3.1.但它在iOS 11测试版中不可见.
有没有人遇到过这个问题?
我想设置UITableView以匹配表视图中所有内容的高度.
这是我的故事板
这个问题是顶部和底部的ImageView在屏幕上始终是静态的.
假设桌面视图中有10个项目,但由于屏幕尺寸限制,只有7个项目显示.我希望在用户能够看到底部的ImageView之前显示所有10个.(顺便说一句,所有3个视图,即图像视图和tableview都在uiscrollview中)
理想
我必须处理的一些其他限制是表视图中的项目数是动态的,这意味着它可以是任何通常小于10的数量,我稍后将从api中检索.根据内容,细胞高度也是动态的.
我刚刚开始使用一些简单的代码
class ExampleViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var items: [String] = [
"Item 01", "Item 02", "Item 03", "Item 04", "Item 05",
"Item 06", "Item 07", "Item 08", "Item 09", "Item 10"]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.items.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell
cell.textLabel?.text …Run Code Online (Sandbox Code Playgroud) 有一种方法可以NSArray IBInspectable在Storyboard自定义视图中定义多个值吗?
我知道NSArray没有关于将存储在其中的对象类型的任何信息,所以它可能是一个问题.但是有一些解决方案使用注释或其他东西?
我想要做的是设置NSArray的UIColors通过故事板和可视化的故事板绘制在视图中的渐变层.
我开始创建两个名为startColor和endColor的属性.这工作正常,但我想这样做更通用.
这是我的drawRect方法:
- (void)drawRect:(CGRect)rect {
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.bounds;
gradientLayer.colors = [NSArray arrayWithObjects:(id)[self.startColor CGColor], (id)[self.endColor CGColor], nil];
[self.layer addSublayer:gradientLayer];
}
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情:
- (void)drawRect:(CGRect)rect {
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.bounds;
// colorsArray should be an IBInspectable property in order to be setted on Storyboard Attributes Inspector
gradientLayer.colors = self.colorsArray;
[self.layer addSublayer:gradientLayer];
}
Run Code Online (Sandbox Code Playgroud) 我正在努力使我的应用程序与iOS 10 beta兼容.但不幸的是,应用程序一开始就崩溃了.我已经检查了Main.storyboard中的所有IBoutlet和连接,这些都非常好.它也适用于iOS 9.3.2,即Xcode 7.3.
请帮忙.提前致谢.
我正在尝试使用Swift迭代我放入Assets文件夹的图像.我想迭代它们并.nib稍后将它们插入到文件中,但到目前为止我找不到如何得到类似的东西:
let assetArray = ["image1.gif", "image2.gif", ...]
这可能吗?我一直在玩,NSBundle.mainBundle()但在这方面找不到任何东西.请告诉我.谢谢!
我已完成图像上传,并使用以下方法成功上传到服务器上.
现在我想上传图像及其进度,以便有人告诉我该怎么做?我在各处找到但没有得到正确的解决方案.
图像上传代码没有它的进展:
@IBAction func uploadClick(_ sender: AnyObject) {
// define parameters
let parameters = [
"file_name": "swift_file.jpeg"
]
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(UIImageJPEGRepresentation(self.photoImageView.image!, 0.5)!, withName: "photo_path", fileName: "swift_file.jpeg", mimeType: "image/jpeg")
for (key, value) in parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, to:"http://server1/upload_img.php")
{ (result) in
switch result {
case .success(let upload, _, _):
upload.responseJSON { response in
//self.delegate?.showSuccessAlert()
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
// …Run Code Online (Sandbox Code Playgroud) 我收到以下错误:
getimagesize(https://static1.squarespace.com/static/570d03d02b8dde8b2642afca/570f74e87c65e4819dec6812/57272dbfb6aa606f78a5d8b5/1470397291105/4XTRYCK3.jpg):无法打开流:HTTP请求失败!HTTP/1.1 400错误请求
我的浏览器中的图像打开没有问题.
有谁知道为什么会失败?
我正在完成本教程,它在模拟器上运行得很好,除了我不明白如何调用这些方法.今天的视图小部件显示正常,但是当我向方法添加断点时(例如ViewDidLoad,widgetPerformUpdateWithCompletionHandler),似乎永远不会调用断点.
我正在尝试解决这个问题,因为我添加了额外的代码 - 例如NSLog在方法中显示一些值但是没有看到NSLog调用的任何输出.
有人能解释为什么断点不起作用吗?我猜它与扩展方法有关,正在'背景'中执行,但我不确定.
谢谢
ios ×9
objective-c ×4
swift ×4
uitableview ×2
alamofire ×1
cocoa-touch ×1
gd ×1
getimagesize ×1
ibdesignable ×1
iphone ×1
keyboard ×1
nsarray ×1
php ×1
swift3 ×1
uibutton ×1